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?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Linux for Beginners

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

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Ad