Learn the basics of cron

table of contents
This is Nakagawa from the System Solutions Department.
This time, I'll be writing about the basics of cron.
What is cron?
This is a daemon process for UNIX-like operating systems that executes commands at scheduled times. It
such as "Execute command XX every day" or "Execute command XX every hour
automatically executes commands at set times,
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 it to "*" selects everything. In other words...
it's a process that "writes 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 look at cron settings in my operations,
and for example, if the load is increasing, it could be due to a heavy process set up in cron.
If the load suddenly increases at a specific time, like XX:00, and
you check with the ps command and see that a cron process is running,
looking at the cron settings might give you a clue to solving the problem.
2
