Environment
Novell Open Enterprise Server (Linux based)
Novell SUSE Linux Enterprise Server
Novell SUSE Linux Enterprise Desktop
Novell SUSE Linux
Novell SUSE Linux Enterprise Server
Novell SUSE Linux Enterprise Desktop
Novell SUSE Linux
Situation
How to schedule tasks, commands, or scripts to execute at specific times or intervals.
Resolution
crontab, cron.hourly, cron.daily,or cron.monthly allow scripts or commands to be run at specific times or intervals.
Additional Information
Cron jobs can be scheduled in many different methods with the most common being using /etc/crontab to schedule the script or command. This file is separated into seven columns with the format and description as follows:
minute hour day month dayofweek user command
- Minute an integer from 0 to 59
- Hour an integer from 0 to 23 (a 24 hour clock is used)
- Day an integer from 1 to 31 (this must be a valid day for the given month. For exampleFeb 31will not work)
- Month an integer from 1 to 12
- Dayofweek integer from 0 to 7 where both 0 and 7 represent Sunday
- User the user who cron will use to execute the command
- Command the desired command to execute. This can be a script or a normal command like
hwinfo >> hardware.txt
*** Please note that when a task is scheduled using cron it is common for the job not to run the first time but will run the second time it is scheduled. This is by design and is mentioned here as an aid to the user. Commonly new scripts or commands are scheduled in crontab to run frequently while verifying the results before the script or command is copied to the cron.daily, cron.hourly, cron.monthly directory.
- Use the date command in the beginning of the script as a check to verify if the script was called. A simple
date >> /tmp/scripttestplaced at the top of the script enables a quick check to see if the script was called and processed. The scripttest file will reveal when the script was called and when the date command was executed. - If the date command reveals the script is running but the desired result of the script is not realized there is a problem with the script. With cron jobs, any output that would normally go to the screen is lost. Redirecting the output and errors to a file may help discover the problem, for example
mycmd> /tmp/script.out 2>&1