Also short for ‘chronograph,’ cron refers to a non-interactive program that executes commands at specified time periods or intervals even when unattended. A cron job automates repetitive tasks, such as periodically deleting mails in an e-mail account to minimize use of disk space, rotating log files, deleting subscribers or members of your Web site with expired accounts or changing features of your Web site.
The cron system reads various cron tab files that are found either in a users’ directory. The cron tab files may be edited with either the cron tab command or by editing the various files within the directory.
Cron jobs offer flexibility as they can be set to function in the exact minute, hour, day, week or month, depending on your desired settings. Daily quotes and blogs in a Web site that are updated every day are basic examples of cron jobs. Cron jobs can also periodically delete mails in an e-mail account to help in reducing disk space usage. In addition, a cron job can also aid users in “rotating” log files.
Follow these steps to automate your tasks using cron jobs:
1. Open System Settings, hit the Advanced tab, followed by Task Scheduler.
2. Decide if you want to run either a Personal Cron or a System Cron. The Personal Cron affects only your own user space, while the System Cron affects all users on which your system works. Click New Task.
3. Learn how cron views time. The cron time structure looks like this:
Minute-Hour-Day of month-Month-Day of the Week
The cron system looks at time like this:
* Minute (0-59)
* Hour (0-23)
* Day of the month (1-31)
* Month (1-12)
* Day of the week (0-6 with Sunday being 0)
4. Enter the command, browse, or begin typing the path and it will show you a list of commands in that folder in a drop-down menu.
5. Cron requires that you add the symbol “*” for sections that you do not have any entries. Therefore, for a cron job that you want to run at 8am every day of the week, you will put in “0 7 * * *” for the time portion.
6. Edit your cron entries using the cron tab command. These are few of the switches for the cron tab command:
* e – Edit your crontab
* l – List your crontab
* r – Delete all crontab entries
To add new cron tab entry, put in the command cron tab “-e”
7. Press Esc to go out of the insert mode. Write the file and quite the cron tab by hitting the “:” button followed by “wq”, which means “write and quite. Finish the job by hitting the Enter key. You should see “cron tab: installing new cron tab” at the bash prompt.
With cron jobs, you have the power to automate and schedule your tasks as you deem necessary, and for as often as you want.
Related Posts:
