You can get the advice from IT HELP DESK

SYSTEM[LINUX] How to use crontab

15 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

[LINUX] How to use crontab

1. cron?

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.

#crontab -e

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 every minute

*     *     *     *     *     /home/

  2) Run every Monday at 2:30 am

30     2     *     *     1     /home/

  3) Run every hour at 0, 15, 30, and 45 minutes every day

0, 15, 30, 45     *     *     *     *     /home/

  4) Run every minute from 3:00 to 30 minutes every day

0-30     3     *     *     *     /home/

  5) Run every 6 hours (00:30, 06:30, 12:30, 18:30)

30     1-23/6     *     *     *     /home/

3. Check cron

To check the registered cron, use the following command.

#crontab -l

# 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.

#crontab -r

Finally, the history of changes or performance of cron can be found in /var/log/cron.