[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Learn about the basics of cron

This is Nakagawa from the System Solutions Department.
This time I will write about the basics of cron.

What is cron?

A UNIX-based OS daemon process that executes instructions at a registered time.
"Run XX command every day" "Run XX command every hour" The
command will be automatically executed at the time you set.

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

-Basically, as shown above, from left to right: "minute", "hour", "day", "month", "week", and "execution command".

actually write it

* * * * * echo "test01" >> /var/www/html/CronTest_01.txt ## Run every minute

・If you set "*", all will be selected.In other words,
it will be "the process of writing test01 to /var/www/html/CronTest_01.txt every minute".
Save this file and after 3 minutes...

$ less /var/www/html/CronTest_01.txt

test01 test01 test01

In this way, the CronTest_01.txt file is created and 3 lines are written because cron was executed 3 times.

10 * * * * echo "test02" >> [Execution command] ## Execute at the 10th minute of 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 is executed even though I set it to 15:00 on the 26th.

10 20 * 1 * echo "test04" >> [Execution command] ## Execute at 20:10 in January

The command is executed even though I set it to 20:10 in January.

The week can be set as a number from 0 to 7, as shown below.

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 on Sunday at 3:00

The command will be executed when set to 3:00 on Sunday.

30-40 * * * * [Execution command]

In addition, if you write as above... The command set in 1 minute increments will be executed from 30 minutes to 40 minutes.

I think now you can also read when cron is executed even if it is set by someone other than yourself.

summary

I often check cron settings during operation,
for example, if the load is increasing, it may be due to heavy processing set to cron.
If the load suddenly increases at a timing like 〇〇:00, or
if the cron process is running when you check with the ps command,
looking at the cron settings will give you a clue to the solution. Maybe.

If you found this article helpful , please give it a like!
1
Loading...
1 vote, average: 1.00 / 11
1,869
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Tsuyoshi Nakagawa

the company in August 2017
and worked in the infrastructure team for about a year and a half, and is currently in the technology sales department.
His hobby is online window shopping.

■ Qualification
LPIC1
AWS Certified Cloud Practitioner