Cron/Crontab Question
In the past I have put entries in my crontab in the following form:
0 6 * * 6 cd /root/scripts; ./backup_net.sh; > /dev/null 2> /dev/null Can someone explain to me exactly what the > /dev/null and 2> /dev/null do? What I would like to happen is to get emailed with a simple success or failure. If the > /dev/null and 2> /dev/null are left off I get sent the output of the commands which could be lengthy. Any thoughts? |
With the command you've posted the shell will redirect error output (2) to std output and pipe std output (1 or nothing) to null.
You could squish that as "2>&1>/dev/null" . If you only want the error output, just pipe stdout to null: </path/to/>backup_net.sh > /dev/null If you OTOH want better control over error output best thing is to rework your backup script to use error values. An example could be: cmd=bin/false; ${cmd} 2>/dev/null; case "$?" in 0) printf "%s${cmd} went OK\n";; 1) printf "%sError running ${cmd}\n";; *) printf "%sError running ${cmd} (err: $?)\n";; esac ...which will return 127 for "command not found", if you fix the path, it will return "1", as false always will. |
unSpawn is right - what I also do though is output to a file - eg
0 6 * * 6 cd /root/scripts; ./backup_net.sh; 2>&1>/tmp/mycron.log Then create a scipt that e-mails me mycron.log (or a parsed version that only sends lines with errors on it) |
All times are GMT -5. The time now is 12:31 AM. |