100 Useful Command-Line Utilities
by Oliver; 201482. crontab
crontab is a tool to automatically run a command or script at periodic intervals. The first hit on Google has a nice how-to about crontab: To quote directly from this source, you need to make a file of the form:Field | Range of Values |
minute | 0-59 |
hour | 0-23 |
day | 1-31 |
month | 1-12 |
day-of-week | 0-7 (where both 0 and 7 mean Sun, 1 = Mon, 2 = Tue, etc) |
command-line-to-execute | the command to run along with the parameters to that command if any |
Once you make a file of this form, you can run it. For example, if:
$ cat mycron.txt 45 10 * * * rm -r /full/path/trash/* > /full/path/out.o 2> /full/path/out.eThen you run this as:
$ crontab mycron.txtAnd it will empty the trash folder every day at 10:45 a.m.
Display your cron jobs:
$ crontab -lOne peculiar thing about cron is that, if you're on a shared computer system, your system administrator might be the one running cron in his name and, when you invoke cron, you won't start a process running under your name. For this reason, you have to use absolute paths in the commands you put in your cron job: cron doesn't know about the local folder from which you run the command.