Saturday, December 29, 2012

Get CRON to Send Email Reports

Here is a quick tip: if you have CRON running jobs, but want assurance they're getting done by way of email, do the following:
Open CRON:
crontab -e
You'll see something like this:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command

28 * * * * cd /home/joseph/google_drive && grive
Now add the following line to the end of the file:
MAILTO=somebody@your.domain
Then Save and Close; as long as you have a mail server set up and running, you'll get an email with the output of each of the commands in the file every time they're run.

If You Don't Have a Mail Server

If you don't have a mail server set up, and are running Ubuntu, you may want to check out Juju Charms they are Ubuntu's newest way to set up complex server configurations with a single command. Or just follow this tutorial on how to set up Postfix.

No comments:

Post a Comment