Friday, September 12, 2014

How to add cron job in CentOS(UNIX/LINUX)

CRON Job is one of the most powerful system in UNIX system. Cron job will be execute by unix system by certain time interval on regular basis. It will allow to schedule your script to run on background without affecting your current task on UNIX machine. Here i will give you real time example for CentOS.

Cron jobs can be schedule on two different ways, System cron job and user defined cron jobs. System jobs will be defined by root privilege user. This will allow your unix system to perform there system related job on certain interval basis. User defined cron jobs can be defined by any of the user with their user privilege.

Location of crontab in CentOS - /etc/crontab

The below command will allow you to edit the cron file to add your job.

crontab -e

Here the syntax for adding your cron job into cron file.

1 2 3 4 5 /path/to/your-filename arg1 arg2

What is 1, 2, 3, 4, 5?

1 - Minute (0-59)
2 - Hours (0-23)
3 - Days of month(1-31)
4 - Month (1-12)
5 - Week days (0 -7)

You can pass your arguments with arg1, arg2 and argN

To list your cron jobs - crontab -l

To Remove all cron job - crontab -r

No comments:

Post a Comment