Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring,
[LINUX] How to use crontab
cron (cron) is a daemon for making commands (programs) at the desired time.
For example, there is a backup program that needs to be run every day at 3 am. It is almost impossible for a person to stay at dawn and run the program. If you need to run the program at a certain time or cycle, it is cron.
cron will execute the command at the set time.
2. Register cron
Enter the following command to get the vi editor. Instruct new work here and save it as: wq.
The cycle setting method is as follows.
At this time, 1 is Monday, 2 is Tuesday, and 0 is Sunday. You must enter one command per line, and you can not divide it into two lines. # Is a comment, so do not run it.
The cycle can be set using *, - /. Using, multiple time zone can be set, and - using the time range can be specified. You can also use - and / to specify the time interval.
Please refer to the example below for each cycle and register!
1) Run test.sh every minute
* * * * * /home/test.sh
2) Run test.sh every Monday at 2:30 am
30 2 * * 1 /home/test.sh
3) Run test.sh every hour at 0, 15, 30, and 45 minutes every day
0, 15, 30, 45 * * * * /home/test.sh
4) Run test.sh every minute from 3:00 to 30 minutes every day
0-30 3 * * * /home/test.sh
5) Run test.sh every 6 hours (00:30, 06:30, 12:30, 18:30)
30 1-23/6 * * * /home/test.sh
3. Check cron
To check the registered cron, use the following command.
# Please note that we will not run the comment processing part.
If you want to delete the registered cron, you can delete it all at once by the following command. When executing this command, all registered cron will be deleted. Therefore, it is recommended to modify crontab -e as described above.
Finally, the history of changes or performance ofcron can be found in /var/log/cron.