create Cron Jobs


Cron is a time-based job scheduler in Unix-like computer operating systems.
Cron table files (crontabs) are stored in /var/spool/cron, which is not accessible by non-privileged users. In order to access the current crontab, the crontab command is used.
The crontab can either be edited in the current direcrtory and installed by using it as an  argument to crontab or by using the -e option.

Events scheduled by cron are run by the crond daemon, which must be running on the system.
---------------------------------------------------------------------------------
Option    Meaning
___________________________________________________
-u user   Install crontab for user.(Must be privileged to use
-e        Edit the current crontab using the editor specified in 
          VISUALor Editor  environment variables
-l        List the contents of the current crontab
-r        Remove the current crontab
___________________________________________________
Example
#crontab [ -u user ] file
# crontab [ -l | -r | -e ]
System Crontab Files
 The format of /etc/crontab and the files in /etc/cron.d are different from user crontabs. The sixth field is a username which will be used to execute the command in the seventh field.
A common command in these files is the run-parts shell script. This script takes one argument, a directory name, and invokes all of the programs in that directory (The run-parts scripts is located in /usr/bin and has no online documentation.)
The following is an example /etc/crontab file;
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin
MAILTO=root
HOME=/
#run-parts
01 *  *  *  *  root run-parts /etc/cron.hourly
02 4  *  *  *  root run-parts /etc/cron.daily
22 4  *  *  0  root run-parts /etc/cron.weekly
42 4  1  *  *  root run-parts /etc/cron.monthly
Step No 2, describes that at 4.02 every morning, all of the executables in the /etc /cron.daily directory will be run as root.


 
 

0 comments:

Post a Comment