Thursday, January 9, 2014

Working With Cron

Cron:
Cron is a software which is used for time based job scheduling. It is basically used in Unix/Linux operating system. Those who want to set up software environment can use cron to scheduling job. Its script run automatically after a time of interval which we set . We can use this cron for connecting the internet or receiving the email at a regular interval.

Cron is driven by crontab file which is a configuration file used for run the script accordingly its schedule. Every line in crontab file represents a job. In these lines we add a time interval in which a particular task will be performed.

Examples of Cron:

1. If we want to perform any job at the mid - night (00:01) of every day of week, then we can write it as

1 0 * * *  printf > /var/log/apache/error_log

2. If we want to perform any job at after 2 hours like 2am, 4am, 6am and so on

0 */2 * * *  /home/username/test.pl
00 20 * * * /home/oracle/scripts/export_dump.sh

These five position which is currently define as * having there own values

These are following as accordingly :

# * * * * *  command to execute
# ┬ ┬ ┬ ┬ ┬
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sun to Sat, or use names; 7 is Sun, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)

Cron Permissions:

There are basically two files , which are used for it permissions.

1. /etc/cron.allow - If this file exists, it must contain your username for you to use cron jobs.
2. /etc/cron.deny - If the cron.allow file does not exist but the /etc/cron.deny file does exist then, to use cron jobs, you must not be listed in the /etc/cron.deny file.

No comments:

Post a Comment