Mac OS X is a Unix system and so can be used as a Unix system with all the normal commands and services found on a Unix system.
I discovered recently that every thing was installed to use cron on my Mavericks (10.9) system.
cron - daemon to execute scheduled commandsThe goal of cron is to run commands periodically. For example your can start a backup command or a Jenkins job on a regular schedule.
Mail configurationcron sends its output and error messages by email. So you need to have your email configured correctly.
Sending an emailBy default email is already working on Mac OS X for a local delivery. You can check it using:
$ date | mail -s test rousseauOf course you use your own login name instead of rousseau.
This command will send the time and date in an email to rousseau with subject "test".
You should not have any output from the command unless you get an error.
If your mail server require an user authentication you may need to configure your Postfix local configuration.
Reading an emailThe same command
$ mail Mail version 8.1 6/6/93. Type ? for help. "/var/mail/rousseau": 1 message 1 new >N 1 rousseau@iMac-de-Lud Sun Feb 15 13:30 14/538 "test" ? press Enter Message 1: From rousseau@iMac-de-Ludovic.local Sun Feb 15 13:30:01 2015 X-Original-To: rousseau Delivered-To: rousseau@iMac-de-Ludovic.local To: rousseau@iMac-de-Ludovic.local Subject: test Date: Sun, 15 Feb 2015 13:30:01 +0100 (CET) From: rousseau@iMac-de-Ludovic.local (Ludovic Rousseau) Dim 15 fév 2015 13:30:01 CET ? d ? q $
Here we can read our test email. Then delete it using the "
d" command and quit using the "
Redirecting your emailsMaybe you do not read your email using the
$ cat ~/.forward firstname.lastname@example.org
Test again to send you an email and check the redirection is working.
Cron configurationcron uses a crontab to store the user configuration. Each user has its own crontab configuration. Use the shell command
crontabto edit the configuration.
vicrontab uses the editor configured in the EDITOR environment variable or vi by default.
The problem with vi (or vim) is that vi exits with a return value that is considered as an error by crontab:
$ crontab -e crontab: "vi" exited with status 1And all your edition is lost.
A solution found at "Error adding cronjobs in Mac OS X Lion" is to use nano instead of vi:
$ EDITOR=nano crontab -e
But I do not like nano and really prefer vim. So another way to solve that is to create a file (you may use the TextEdit graphical application to edit the file but take care to use the Text and not RTF format). I named my file
$ cat Documents/crontab # Every hour 0 * * * * echo "pouet"
Then install it using:
$ crontab Documents/crontab
Check your configuration has been accepted using:
$ crontab -l # Every hour 0 * * * * echo "pouet"
Read the crontab section 5 manual page (
man 5 crontab) to know the format to use.
ConclusionNo need to install a graphical tool to periodically run a command on Mac OS X.
Mac OS X is and stays a Unix system under the graphical interface.