CRON JOB – Scheduling Jobs in Linux

Scheduling Jobs in Linux with CRON(CRONTAB)

CRONTAB is a very useful utility in Linux to schedule your day to day jobs.CRONTAB or CRON simply runs commands or scripts at a scheduled time.

In this article, we will learn scheduling Jobs in Linux with CRONTAB. We will take examples to understand it.

Also Read :  How to install Jenkins on Ubuntu

&&  Create your First Build Job in Jenkins

 CRONTAB Commands

Below are the important crontab commands that we must know.

       1.Add a new Job in CRONTAB

        $ crontab -e

This command will open an empty file. You need to put your commands or scripts here to run your command or script automatically at a particular interval of time.

      2. Display all Scheduled Jobs in CRONTAB

          $ crontab -l

This command will display all scheduled jobs.

  • CRONTAB Format

Below is the format of CRONTAB or CRON that we put in CRONTAB – I command.

          * * * * * /path/to/script.sh

            Here definition of * * * * *  are as follows:

min hour day of month month of year day of week
0-59 0-23 1-31 1-12 0-6

Examples :

1.  A Script is scheduled to run 5:10 AM every day.

 

2.  A Script is scheduled to run 5:10 AM to 5:20 AM every day.

 

3.  A script is scheduled to run every 5 min.

 

4.  A script is scheduled to run at 11 AM on 10th of March

 

5.  A script is scheduled to run at 1 AM every Saturday.

 

6. A command to restart MySQL service at 10 am every day.

    3.Remove current Job in CRONTAB
      $ crontab -r

     4.Prompt before removing a CRONTAB.

           $ crontab -ir

     5.Add and display CRON for a particular user.

Use “- u username” after crontab -l or crontab -e to display or edit crontab for a particular user.

        $crontab – l -u username

        $crontab -e -u username

     6.List name of the users who have CRONTAB jobs.

      $ ll /var/spool/cron

This article ends here.

Hope you enjoyed this article, please feel free to give us comment in the Comment box. If you liked this, please do share this article  to others as well.

Thank You

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

You may also like…

Leave a Reply

Your email address will not be published. Required fields are marked *