Cron

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

The cron is daemon to execute scheduled commands. cron is started automatically from /etc/init.d directory or can be controlled using the service command.

Cron jobs

Cron job are used to schedule commands to be executed periodically. You can setup setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.

How does cron works?

cron wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output.

crontab command

The crontab is the command used to install, deinstall or list the tables (cron configuration file). Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

How do add my own cron jobs?

See also