Schedule a task in linux using crontab

Hi Readers,

I am happy to post another blog post on how to schedule a task in linux using crontab.

cron enables users to schedule jobs to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration. cron checks for scheduled jobs every minute but not every second.

 

* * * * * command or shell script to be executed
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 6) (0 is Sunday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)

Use the below command to check existing cron that has been scheduled in the linux box.

$ crontab -l

Use the below command to edit the cron entries.

$ crontab -e

 

Schedule a job to run everyday at 12.10  am.

10 0 * * * /usr/jpraveen/testautomate.sh

Schedule a job to run every sunday at 12.10  am.

10 0 * * 7  /usr/jpraveen/testautomate.sh

Schedule a job to run only on weekends at 12.10  am.

10 0 * * 6,7  /usr/jpraveen/testautomate.sh

Schedule a job to run everyday  at 9  am and 6 pm.

0 9,18 * * *  /usr/jpraveen/testautomate.sh

 

Thanks for reading this post. Subscribe my blog for  some awesome posts.

Happy Learning !!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s