LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-09-2003, 07:30 AM   #1
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
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?
 
Old 04-09-2003, 09:11 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,470
Blog Entries: 54

Rep: Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900
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.
 
Old 04-09-2003, 01:09 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
atq details - cron/crontab nadine.mauch Linux - Software 2 01-03-2005 02:01 AM
Extra cron jobs not in "crontab -e"? inspleak Linux - General 2 07-21-2004 09:47 PM
crontab vs cron.daily ? SheldonPlankton Linux - Newbie 1 07-16-2004 12:10 PM
crontab question DriveMeCrazy Linux - Newbie 1 05-23-2004 12:25 PM
Cron/Crontab loocw Linux - General 2 03-08-2001 02:16 AM


All times are GMT -5. The time now is 06:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration