exec redirect keeps file pointer

Posted on 2007-08-08
Medium Priority
Last Modified: 2013-11-14
I have a script that includes

exec 1>> /var/log/unb/dblog.log

later logrotate renames the file to ...dblog.log.1 as expected but the script continues writing to the same file so the dblog.log.1 just gets bigger rather than starting to write to a new dblog.log as I expected. how can I get my expected behaviour
Question by:NickUpson
  • 2
LVL 48

Assisted Solution

Tintin earned 800 total points
ID: 19652723
In your script put

trap 'exec $0' 1

To restart it if it gets a SIGHUP make sure you have a

pkill -HUP yourscript

in the appropriate file in /etc/logrotate.d
LVL 43

Expert Comment

ID: 19653017
If the script takes no parameters, then it's otherwise

function huphandler { exec 1>>/var/log/unb/dblog.log; }
trap huphandler SIGHUP
#and initialize log

rest of script
LVL 19

Author Comment

ID: 19653213
The script runs in a loop with a sleep

do( 0 = 0 )
 sleep 90

could I just cause the "exec 1>>/var/log/unb/dblog.log" to be reexecuted every time round the loop to get the same effect
LVL 43

Accepted Solution

ravenpl earned 1200 total points
ID: 19653269
Yes. before <stuff> i guess.

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question