Linux Cron Job – Schedule Job in linux: crontab

In all Operating system there option to schedule a job/activity that should be run on particular time interval.

Here is an introduction to job scheduler in linux, called crontab. Cron allows tasks to run automatically in the background at fixed time or time intervals depending upon the necessity of the task that has to be executed. We normally use cron jobs to automatically take backup from servers, or synchronise different folders or files and much more.

The task that is to be executed is known as a cronjob, and crontab can be defined as a table that stores the list of cronjobs that are being executed in a system. (The word “Cron”derived from “Chronos” which in greek means “Time” and “Tab” refers to “Table”. So crontab effectively means timetable).

cronjob linux job scheduleHere is some basic crontab file operation.

  1. To know the list of cron jobs that is running on your system, just open a terminal and type in the following command:
    crontab -l

    2. In order to edit this crontab file, you can use the command

    crontab -e

     

    3. lists all cron jobs of a user., you can use the command

    crontab -u exampleuser -l

     

    4. To Deletes all cron job, you can use the command

    crontab -r

     

    5. To Deletes all cron jobs of user, you can use the command

    crontab -u example -r

     

    For Short notes

     Removing a cron job:

    Removing a cronjob is easy, just delete the cronjob line set in the crontab file and then save the changes in the crontab file. you can also execute the command crontab -r to remove all the cronjob.

     

    Disabling a cron job:

    To disable a cron job without actually removing it from the file, you can just comment it out by adding a ‘#’ to the beginning of the line.

     

    Adding a cron job:

    To add a cronjob you have to understand the format of a cronjob line.

    Cronjobs are written in the following format:

     

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

     

    Here the five stars represent various time/frequency parameters – minute, hour, day of month, month, day of week, respectively.

     

    Minute – (0-59)
    Hour – (0-23)
    Day of month – (1-31)
    Month – (1-12)
    Day of week – (0-6) “Number 0 in week refers to sunday”

     

    Using ‘*’ to denote different frequencies:

     

    '*' stands for 'every',
    '*/2' stands for 'once in every two minutes', 
    '*/3' stands for 'once in every three minutes'.

     

    After these five stars you have to give the path where the script is located.

    Examples:

    The following examples should help you get a clearer understanding:

     

      * * * * /path/to/command/to/be/run

     

    would mean you want to run the script every minute of every hour of every day of the week of every month of every year. This simply means that the script will get executed in every single minute.

     

      */2 22 8 12 * /path/to/command/to/be/run

     

    would run the command once every 2 minutes, during the 22nd hour of the 8th day of the month, in the 12th month (December), whatever be the weekday (‘every’).

     

Related Posts

  • 60
    The vi Editor http://t4test.com/blog/unix-linux-shell-script-introduction-to-shell-scripting/ http://t4test.com/blog/read-making-shell-script-interactive/ http://t4test.com/blog/cpio-a-backup-program/ Backup Using TAR Backing up your files using tar is very simple you just type a little command. tar -cvpzf /BackupDirectory/backupfilename.tar.gz /ImportantData/directory/path Let’s suppose i have directory called /imp-data on root and i want to make backup of this directory including sub directories on…
    Tags: command, file, crontab, cron, linux, month, job, day, jobs, time
  • 45
    There are various method to execute php file via crontab in linux. Here is the details of all the method: Method 1: Run the php script using URL from the crontab If your php script can be invoked using an URL, you can lynx, or curl, or wget to setup…
    Tags: crontab, file, linux, job, cron
  • 42
    Use the blow command to set the linux date #date 072511242014 where 07= mm (Month) 25=dd (Date) 11=hh (Hour) 24=mm (minute) 2014=yyyy (Year)
    Tags: linux, command, minute, hour, month, time

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

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

%d bloggers like this: