03. Handling Crontab Outputs

When running cron jobs, you'll often have some output. If you have a mail client installed, it will send to the email address. If not, it will be sent to /dev/null (aka be discarded). either to standard out or error. You can redirect this to your e-mail.

Mailing output

By default, the output to a cron job will be mailed to whoever owns the process, or whatever the MAILTO variable is set as.

To mail the output to someone else, pipe and use the mail command.

00 * * * * echo "Hello! How are you this hour?" | mail -s "subject of mail" username@example.com

Trashing the output

If you don't want to email altogether, redirect to /dev/null, which is a folder that essentially acts as a trash bin.

0 * * * * echo "No need for this message." >> /dev/null

Appending to a log file

We may also append to a log file, or to both standard out and error by redirecting it.

0 * * * * echo "redirect" >> log.file
0 * * * * echo "redirect" >> log.file 2>&1

Aching back from coding all day?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

The Linux Command Line

Take your Linux skills to the next level! Try Linux & UNIX

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources

Ad