• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 975
  • Last Modified:

exec redirect keeps file pointer

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
0
Nick Upson
Asked:
Nick Upson
  • 2
2 Solutions
 
TintinCommented:
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
0
 
ravenplCommented:
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
huphan;

rest of script
0
 
Nick UpsonPrincipal Operations EngineerAuthor Commented:
The script runs in a loop with a sleep

do( 0 = 0 )
 <stuff>
 sleep 90
done

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
0
 
ravenplCommented:
Yes. before <stuff> i guess.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now