How to schedule scripts or commands with cron on SuSE Linux
This document (3842311) is provided subject to the disclaimer at the end of this document.
Environment
SUSE Linux Enterprise Desktop
Situation
Resolution
Additional Information
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.
Troubleshooting cron and custom scripts can be a frustrating experience. A few, easy to use, lines of code can help troubleshoot possible problems.
- 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
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:3842311
- Creation Date: 12-Sep-2006
- Modified Date:15-Mar-2021
-
- SUSE Linux Enterprise Desktop
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com