1. Create a new crontab file for your user, Type the following into the terminal:
#crontab -e
2. Choose when you would like the job to run. Every jod is a line in your crontab file. The first 5 arguments specify the time to run the job, and the 6th argument is the command to run.
Argument 1: Minute (0 - 59)
Argument 2: Hour (0 - 23)
Argument 3: Day of Month (1 - 31)
Argument 4: Month (1-12)
Argument 5: Day of Week (0 - 6) Sunday = 0
Argument 6: Command
e.g:
0,20,40 * * * * cat /var/log/system.log >> /home/user/logfile.txt 2>&1
will get the log file on system.log at the 0th, 20th, 40th of per hour, and redirect the content to logfile under /home/user.
30 12 * * * touch testfile
will touch a file which name is testfile at 12:30 everyday
Save the file, and crontab should report:
crontab: installing new crontab
Notes: On Mac OS, don't restart the cron service after edit crontab of user
3. To see a list of your crontabs, run this command:
# crontab -l
4. To remove crontabs, run this command:
# crontab -r
For more detailed-chinese information about Cron, please refer to Cron用法说明 and Cron Help Guide