Monday, December 28, 2015

crontab

Scheduling at OS can be performed in the following ways

1) Using crontab

* Crontab stands for cron table, Which dervied from greek word chronos (Chronos means time).
 * To schedule multiple system events at regular intervals we use crontab.
* Each user can have their own crontab.
* The location of the crontab files is /var/spool/cron/crontabs.
* The crontab files which control the access are /etc/cron.d/cron.allow and /etc/cron.d/cron.deny.
* cron jobs can be allowed or disallowed for individual users, as specified in the files cron.allow and cron.deny
* A user should be placed in the cron.allow to get access to the crontab.
* If the cron.allow file does not exist but the cron.deny file does, then a user must not be listed there in order to use a given    command.
* If neither of these files exists, only the superuser will be allowed to use a given command.
* Blank lines and leading spaces and tabs are ignored.
* If an entry in the crontab starts with # then the line will be treated as a commnet
* Comments cannot be allowed in the same line as cron commands,

2) Using at

* To schedule a single system event we use at
* The location of the at is /var/spool/cron/atjobs.
* The at files which control the access are /etc/cron.d/at.deny.


Crontab entry format should be as follows

m h dom mon dow <File name>

m - Minutes (0-59)

h - Hours (0-23)

dom - Date of Month (1-31)

mon - Month (1-12)

dow - Day of Week (0-6) ==> 0 means Sunday and 6 means Saturday


* Crontab entries can be listed by contab -l

* To view the your crontab, crontab -v

* crontab can be Edited by crontab -e

* Saving the edited crontab can be carried out as follows

Esc + :wq + Enter

we get the following message

crontab: Installting new crontab and the control will be returned to the command line.

* To remove crontab, crontab -r / contab -i which prompts [Y|N] before removing crontab.

Examples of crontab

Database full backup at 09:10 AM on every sunday.

10 09 * * 0 /home/oracle/Backup-Full.sh

Database incremental backup daily at 08:30 PM except on sundays

30 20 * * 1-6 /home/oracle/Backup-Incr.sh

Archivelog backup at every 3 hours starting at 12:00 AM

00 00,03,06,09,12,15,18,21 * * 1-6 /home/oracle/Backup-Archive.sh

Note: I have posted the examples without testing the commands, Please make sure to check it in practice system.The notes is based on my understanding.


Thanks,

No comments:

Post a Comment