daily cron job output being sent to - BSD

This is a discussion on daily cron job output being sent to - BSD ; I recently turned off daily/weekly/monthly notification for the periodic scripts, since I can just look in the logs if I'm interested (and my little site pretty much takes care of itself). I noticed that if I have the daily periodic ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: daily cron job output being sent to

  1. daily cron job output being sent to

    I recently turned off daily/weekly/monthly notification for the periodic
    scripts, since I can just look in the logs if I'm interested (and my
    little site pretty much takes care of itself).

    I noticed that if I have the daily periodic script backup the root
    filesystem to an altroot, the output from dd will still be sent from cron.

    e.g., I did the following in root's crontab:

    [...]
    ROOTBACKUP=1
    [...]
    # do daily/weekly/monthly maintenance
    30 1 * * * umask 077; /bin/sh /etc/daily
    2>&1 > /var/log/daily.out
    30 3 * * 6 umask 077; /bin/sh /etc/weekly
    2>&1 > /var/log/weekly.out
    30 5 1 * * umask 077; /bin/sh /etc/monthly
    2>&1 > /var/log/monthly.out
    [...]

    I've carefully redirected all output to the periodic logs, but somehow
    the dd command run from /etc/daily, and only that output, is seen by
    crond and passed onto root@

    Any ideas why this might be so?

    I guess I can hack /etc/daily to redirect the output of dd. I'm just
    curious about how the subshells and inherited FDs are allowing this to
    happen.
    --
    clvrmnky

    Direct replies will be blacklisted. Replace "spamtrap" with my name to
    contact me directly.

  2. Re: daily cron job output being sent to

    On 2007-08-21, Clever Monkey wrote:
    > 30 1 * * * umask 077; /bin/sh /etc/daily
    > 2>&1 > /var/log/daily.out


    Don't you really want do something like
    > /file 2>&1

    ?

    Two little tidbits ...
    1) >& and <& duplicate the existing file descriptors.
    2) the shell processes multiple redirects in the order they're given.


    So, you're really saying make 2 a copy of stdout _as it exists now_ (ie
    whatever's been inherited by the environment/cron), then make 1 go to
    the file instead of stdout.

    By reversing then, you point 1 at the file, then copy the new
    descriptor (aka the file) to 2.

    This can be illustrated interactively by running the commands
    print -u2 hi 2>&1 1> /dev/null
    print -u2 hi 1> /dev/null 2>&1

    in /bin/sh. The first prints hi, the 2nd doesn't.

    Switching the order of the redirects may not solve the underlying
    problem if dd or the scripts do funny things with file descriptors.

    --
    ratfood@food.skaterat.net
    All foods should be removed to reply

+ Reply to Thread