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

[Osaka/Yokohama] 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”

cronの基礎について学ぶ

システムソリューション部の中川です。
今回はcronの基礎について書いていきます。

cronとは

登録した時間に命令を実行するためのUNIX系OSのデーモンプロセスです。
「毎日〇〇コマンドを実行」「1時間ごとに〇〇コマンドを実行」これらのように
設定した時間になると自動でコマンドを実行してくれます。

書き方

例)実行コマンド
0~59 0~23 1~31 1~12 0~7 echo "test01" >> test.txt

・書き方の基本は上記のように左から「分」「時」「日」「月」「週」「実行コマンド」となっています。

実際に書いてみる

* * * * * echo "test01" >> /var/www/html/CronTest_01.txt       ## 毎分実行

・「*」を設定するとすべて選択になる つまり・・・
「毎分、 /var/www/html/CronTest_01.txt にtest01を書き込む処理」になっています。
こちらのファイルを保存して、3分経過してみると・・・

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

test01
test01
test01

このようにCronTest_01.txtファイルが作成され、cronが3回実行されたので3行分書き込まれます。

10 * * * * echo "test02" >> 【実行コマンド】      ## 毎時間の10分に実行

〇〇時10分になると設定したがコマンドが実行されます。

0 15 26 * * echo "test03" >> 【実行コマンド】     ## 26日15時に実行

26日の15時00分に設定したがコマンドが実行されます。

10 20 * 1 * echo "test04" >> 【実行コマンド】     ## 1月の20時10分に実行

1月の20時10分に設定したがコマンドが実行されます。

週の設定は、0~7までの数字を設定することができ、以下のようになっています。

0 or 7 1 2 3 4 5 6
0 3 * * 7 echo "test05" >> /var/www/html/CronTest_05.txt     ## 日曜日の3時00分に実行

日曜日の3時00分にに設定したがコマンドが実行されます。

30-40 * * * * 【実行コマンド】

そのほかにも上記のように記述すると・・ 30分から40分までの間1分刻み設定したコマンドを実行します。

これで自分以外が設定したcronでもいつ実行されるかは読むこともできるようになったと思います。

まとめ

自分は運用でcron設定を見ることが多く
例えば負荷が上昇している可能性として、cronに設定されている重い処理などが原因になっていることもあります。
〇〇時00分のようなタイミングで急激に負荷が上昇している場合、
psコマンドで確認したときにcronプロセスが実行されていた場合などに
cronの設定を見てみると解決の糸口になるかもしれません。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
1
読み込み中...
1 票, 平均: 1.00 / 11
1,752
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[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