/sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration
You can also start the service automatically when the system starts:
At the end of the/etc/rc.d/rc.local script, add:
/sbin/service Crond Start
- Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
CRONTAB-L//list details of a user cron service
Crontab-r//Delete a user's cron service
CRONTAB-E//Edit a user's cron service
$ sudo crontab-u <username>-e
- For example, root to view your cron settings: Crontab-u root-l
Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
You will see a text editing window where you can add or edit cron tasks. The Nono editor is used by default.
The format for each cron task is as follows.
- < minutes > < hours > < > < month > < week > < command >
The first 5 elements define the schedule for the task, and the last element is the full path to the command or script.
Here are some examples of cron tasks.
- * * * * * * /home/dan/bin/script.sh: Run every minute.
- 0 ** * */home/dan/bin/script.sh: Run every hour.
- 0 0 ** */home/dan/bin/script.sh: Run at 0 o ' Day.
- 0 9,18* * */home/dan/bin/script.sh: Run at 9AM and 6PM per day.
- 0 9-18* * */home/dan/bin/script.sh: Runs every hour from 9AM to 6PM.
- 0 9-18 * * 1-5/home/dan/bin/script.sh: 9AM to 6PM per hour from Monday to Friday.
- */10* * * */home/dan/bin/script.sh: Runs every 10 minutes.
Once you have completed the above setup steps, press Ctrl+x to save and exit the editor. At this point, the new scheduled task should already be activated.
The crontab file under/var/spool/cron cannot be created directly or modified directly. The crontab file is obtained through the crontab command. Now suppose you have a user named Foxy, and you need to create your own crontab file. You can start by using any text editor to create a new file, and then write to it the command you want to run and the time you want to perform it periodically.
Then save the disk and exit. Assume that the file is/tmp/test.cron. After that, use the crontab command to install the file, making it the user's crontab file. Type:
Crontab Test.cron
When the program is executed at the time you specify, the system will send you a letter showing what the program is doing, and if you do not wish to receive such a letter, please add >/dev/null 2>&1 after each line is empty.
Adding cron tasks to Linux