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

Take your Linux skills to the next level!

System Admin Handbook

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

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Ad