Linux system how to create a scheduled task with crontab

  
                

Scheduling tasks in a Linux system can start tasks on a regular basis. To create a scheduled task, you must first open the crontab service. This article will introduce how the Linux system uses crontab to create scheduled tasks.

crontab to start the service in linux:

/etc/init.d/crond start

crontab command format

crontab -l Display the current crontab file (the default crontab file will be saved in (/var/spool/cron/username for example: /var/spool/cron/roger)

crontab -r delete the current crontab (cautious Use this method because all scheduled tasks will be deleted.

crontab -e Edit the current crontab file using the editor

File format for crontab:

minutes Hour day-of-month month-of-year day-of-week commands

For example:

0 4 * * 2,5 /usr/bin/wall"/etc/motd< Br>

************* Explanation: The information in /etc/motd is broadcast on Tuesdays and Fridays every week*************** *********************************

*/2 12-14 * 3-6, 9-12 1-5 bash_scripts

******************* Explanation: Every year from March to June, and from Monday to Sunday in September and December At 12-14 pm, perform one every two minutes. Scripts *****

The configuration file for crontab is placed in /etc/crontab

The above is the method for creating a scheduled task for the Linux system crontab, if it appears during the execution of the scheduled task. The shell script error, you can refer to: Linux system timing task when the shell script stops executing how to solve.

Copyright © Windows knowledge All Rights Reserved