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


[email protected]:~# tar -czvf vmware-tools-distrib.tar.gz vmware-tools-distrib/

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

[email protected]:~# 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

[email protected]:~# echo hello | xargs -IINPUT echo Your stdin is INPUT
Your stdin is hello


Submit a Comment

Your email address will not be published.

You May Also Like…

MacOS USB Creator

Just toasted my Windows 10 Pro install with a Windows 11 upgrade. Think it will be unrecoverable (because of Bitlocker...