Different Options for Cron Job Standard Output and Error Output

Written by James McDonald

May 15, 2012

A cron job I have created to run a backup script every week day at 5:10PM

# m h  dom mon dow   command
# backup simple invoices and subversion repo
# every week day
10 17 * * 1-5 /usr/local/bin/backup.sh

Here are some different command output redirection options

Redirect standard out to null but still display error messages

# redirect standard out to null
10 17 * * 1-5 /usr/local/bin/backup.sh > /dev/null

Swallow error messages but display the standard output (this can mean alot of output if you use tar -v (verbose))

# redirect standard error to null
10 17 * * 1-5 /usr/local/bin/backup.sh 2> /dev/null

Very quite script. Standard Out and Error directed to the bitbucket (/dev/null)

# redirect standard error and standard out to null
10 17 * * 1-5 /usr/local/bin/backup.sh > /dev/null 2>&1

STDOUT the text displayed in the console when the program /script you are running is going OK


root@computer:~# tar -czvf vmware-tools-distrib.tar.gz vmware-tools-distrib/

STDERR the text displayed in the console when there is something wrong

root@computer:~# tar -czvf vmware-tools-distrib.tar.gz /root/vmware-tools-distrib/
tar: Removing leading `/' from member names

STDIN the command and data you pass into the program / script your are running

root@computer:~# echo hello | xargs -IINPUT echo Your stdin is INPUT
Your stdin is hello


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...

PC Build

I recently built myself a PC using the SilverStone SG13 Case. I am planning to use it as a Hot Spare. So any client...