Scheduling Scripts to Run Automatically

team bbl


Linux allows you to schedule a command to run at a specified time. You can use this ability to schedule scripts to run automatically. You schedule jobs using the crontab command.

The first time you schedule a job, you create a file with the commands you want to schedule. Each command goes on a separate line. The crontab format requires six items on the line, each separated by a space. The items are, in the order of occurrence:

  • Min: Minute to run. Values can be 059.

  • Hour: Hour to run. Values can be 023.

  • Day of month: Day of the month to run. Values can be 131.

  • Month: Month to run. Values can be 112.

  • Day of week: Day of week to run. Values can be 06, with 0 being Sunday.

  • Command: Command to run.

Each item must be present. If an item is not relevant for your scheduling, enter *. Below are two crontab entries that run a shell script:

 59 0 * * * /home/janet/backup 0 2 * * 5 /home/janet/cleanup 

The first line runs the script backup at midnight every night. The second line runs cleanup at 2 a.m. every Friday.

Create a file named crontab that contains entries for the jobs you want to run automatically. To schedule your jobs, type:

 crontab crontab 

This will schedule your jobs. If the command fails, you may need to change to the root account. As root, you can schedule the job for another user, as follows:

 crontab -u janet crontab 

You can see what is scheduled for you by typing:

 crontab -l 

You can change your scheduled jobs by typing:

 crontab -e 

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net