[LINUX] Periodically execute commands with crontab

What is cron?

Processes (≒ functions) that can be used on unix OS (CentOS, Ubuntu, etc.). It is mainly used to run a program that you want to run regularly at a fixed time.

Setting method

$ crontab -e

The vi editor will start up, so write according to the following rules

Minute hour day Monday day of the week username command
*  *  *  *  * root some_command
Target of designation Specified range
Minutes 0〜59
Time 0〜23
Day 1〜31
Moon 1-12 or jan-dec
Day of the week 0-7 or sun-sat

Description example


#Every minute
* * * * * root touch /home/ubuntu/test.txt

# 1:00〜1:Run up to 59 in 1 minute increments
* 1 * * * root touch /home/ubuntu/test.txt

#1 daily:Run to 00
0 1 * * * root touch /home/ubuntu/test.txt

#12th of every month~20th 00:Run to 00
0 0 12-20 * * root touch /home/ubuntu/test.txt

#Every Monday-Friday 00:Run to 00
0 0 * * 1-5 root touch /home/ubuntu/test.txt

option

#Show the configured cron
$ crontab -l 
#Remove all cron,-Be careful not to mistake it for the e option
$ crontab -r

reference

-How to use cron for beginners --Qiita -How to use Cron and where it got stuck-- Qiita -Summary of crontab commands [Linux command collection]

Recommended Posts

Periodically execute commands with crontab
Let's execute commands regularly with cron!
Scripting with Paver-External Commands
Periodically execute python script with cron in venv environment
[Linux] Execute git pull regularly with the crontab command
Commands for creating SNS with Django