Cron is the method of getting Linux to repeatedly do a task at regular intervals. For example, it can automatically produce a backup in the middle of the night or save some status information to a log file. It can send an email reminding people to file their TPS reports every Friday at 2pm.
The key file related to cron is /etc/crontab, and this file along with the /etc/cron.d/ and /var/spool/cron directories, are checked each minute; the crond daemon reads them and decides if there is anything to do.
Ordinary (non-root) users have their cron files stored as /var/spool/cron/crontabs/username. They can add new cron tasks is by using the crontab command. To edit their crontab, they should type in:
crontab -e
Root can edit another user’s crontab by typing in:
crontab -u username -e
Processes can be scheduled with a line containing the instruction in the following format:
Minute Hour Day Month DayofTheWeek Command
An asterisk instead of a number for example in the month column means that it will follow the instruction regardless of which month it is. If you put 1-4 in the day column it will follow the instruction on the first to the fourth of the month, while 1,2,4, means that it will follow the instruction of the first, second and third of the month.
To restrict the use of cron to a particular set of users, or to specifically exclude some users, alter the files /etc/cron.allow and /etc/cron.deny.
Filed under: Processes | Leave a Comment
No Responses Yet to “Cron: scheduling regular processes”