STDERR, STDOUT Script Redirection & Crontab

REDIRECT STDOUT TO NEW FILE

python /etc/cron.d/check_perms.py 1> logfile #create new file or overwrite existing
python /etc/cron.d/check_perms.py 1>> logfile #append to existing

REDIRECT STDOUT TO NEW FILE

python /etc/cron.d/check_perms.py 2> logfile #create new file or overwrite existing
python /etc/cron.d/check_perms.py 2>> logfile #append to existing

CRONTAB REDIRECTION

* * * * * root python somefile.py 1> /dev/null, discards stdout, email stderr if set.
* * * * * root python somefile.py 2> /dev/null, discards stderr, email stdout if set.
* * * * * root python somefile.py 2>&1 , emails both stderr and stdout and combines into one stream.
* * * * * root python somefile.py > /dev/null #sends all output to trash

EMAIL SCRIPT OUPUT FROM CMD LINE

All output…

python ./check_perms.py 2>&1 | mail -s ‘files perms’ jjest@uw.edu

To get output from stderr or stdout you must redirect to file first then to mail address…
*This is the onloy way i can get thish to work!!!

SENDS STDOUT TO EMAIL

$ python stderr.py 2>&1 /var/log/test 2> /dev/null | mail -s ‘yo’ jjest@uw.edu

SENDS STDERR TO EMAIL

$ python stderr.py 2>&1 /var/log/test 1> /dev/null | mail -s ‘yo’ jjest@uw.edu

Leave a Reply