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?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ 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