exec redirect keeps file pointer

Posted on 2007-08-08
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
    LVL 48

    Assisted Solution

    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

    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

    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

    Yes. before <stuff> i guess.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
    Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
    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…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now