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?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Command Line Kung Fu

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

Command Line Kung Fu is packed with dozens of tips and practical real-world examples. You won't find theoretical examples in this book. The examples demonstrate how to solve actual problems. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together.

$ Check price
14.9914.99Amazon 4.5 logo(27+ reviews)

More Linux & UNIX resources

Ad