Learn about the basics of cron

table of contents
This is Nakagawa from the System Solutions Department.
This time I will be writing about the basics of cron.
What is cron?
This is a daemon process for UNIX-based operating systems that executes commands at a registered time. It
automatically executes commands at the set time, such as "execute a command every day" or "execute a command every hour."
How to write
| minutes | time | day | month | week | Example: Execution command |
| 0~59 | 0~23 | 1~31 | 1~12 | 0~7 | echo "test01" >> test.txt |
・The basic format is as shown above, from left to right: "minutes," "hours," "days," "months," "weeks," and "execution commands."
Try writing it yourself
* * * * * echo "test01" >> /var/www/html/CronTest_01.txt ## Run every minute
・Setting "*" will select all. In other words,
it is "Write test01 to /var/www/html/CronTest_01.txt every minute."
If you save this file and wait 3 minutes...
$ less /var/www/html/CronTest_01.txt
test01 test01 test01
In this way, the CronTest_01.txt file is created and three lines are written to it because cron was executed three times
10 * * * * echo "test02" >> [Execution command] ## Execute at 10 minutes past every hour
The command you set will be executed at 10:00
0 15 26 * * echo "test03" >> [Execution command] ## Execute at 15:00 on the 26th
The command will be executed at 15:00 on the 26th
10 20 * 1 * echo "test04" >> [Execution command] ## Execute at 20:10 in January
The command will be executed at 8:10 PM on January 1st
The week can be set to a number between 0 and 7, as follows:
| day | month | fire | water | tree | gold | soil |
| 0 or 7 | 1 | 2 | 3 | 4 | 5 | 6 |
0 3 * * 7 echo "test05" >> /var/www/html/CronTest_05.txt ## Run at 3:00 on Sunday
The command will be executed at 3:00 on Sunday
30-40 * * * * [Execution command]
In addition, if you write it as above, the command you set will be executed every minute between 30 and 40 minutes
Now you should be able to read when a cron command will be executed even if it was set up by someone other than yourself
summary
I often check cron settings during operations,
and for example, a possible increase in load can be caused by heavy processing set in cron.
If the load suddenly increases at a certain time, such as 00:00, and
check with the ps command and find that the cron process is running
, checking the cron settings may provide a clue to the solution.
1