0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Linux】crontabやatを用いたジョブスケジューリング

0
Posted at

基本トピック

cron・crontabの概要

定期的にジョブの実行を行うcronはスケジュールを管理するデーモン(daemon; UNIX・Linux・Mac OSなどにおけるタスクのバックグラウンド実行の際のプロセス)のcrondとスケジューリングを編集するcrontabコマンドから構成されます。

crondデーモンは1分毎にcrontabファイルを調べて、実行すべきスケジュールが存在すればそのジョブを実行します。

atの概要

cronが定期的に繰り返し実行するジョブを扱うのに対し、atコマンドは1回限りの実行スケジュールを取り扱います。atを用いるにあたってはatデーモン(atd)が動作している必要があります。atdは下記のコマンドによって起動することができます。

・atdの起動

$ service atd start

crontabやatを用いたジョブスケジューリングの実行例

crontabを用いたジョブスケジューリングの実行例

atを用いたジョブスケジューリングの実行例

atコマンドは下記のように対話形式でコマンドを指定します。

$ at 17:00 today
at> ls > list.txt
at> Ctrl+D

上記を実行すると当日の17:00ls > list.txtが実行されます。カレントディレクトリはatを実行したカレントディレクトリに対応することに注意しておくと良いです。

書式 日時
22:00 or 10pm 午後10時
noon 正午
17:00 today 今日の午後5時
17:00 tomorrow 明日の午後5時
now + 2 minute 2分後
now + 3 days 3日後
10pm + 2 weeks 2週間後の午後10時

上記にatにおける日時指定の書式をまとめました。運用上は日時指定が用いやすい一方で、動作確認の際はnow + 2 minuteのような表現が用いやすいと思います。また、設定したスケジュールの確認にあたっては下記のようにat -lを実行すれば良いです。

$ at -l
5	Sun Feb  9 17:16:00 2025 
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?