1
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 3 years have passed since last update.

Ubuntu20.04のcron

Posted at

cronファイルの作成

$ sudo cp /etc/crontab /etc/cron.d/cron_test

cron_testファイルの設定

1分ごとにコマンドを実行する設定
※これはDjangoのカスタムコマンドを仮想環境に入って実行して抜ける一連のコマンドです。

cron_test
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

*/1 *   * * *   ubuntu  source /home/ubuntu/djangotest4/.venv/bin/activate && python /home/ubuntu/djangotest4/manage.py cmd_a && deactivate

記法

*[space]*[tab]*[space]*[space]*[tab]user[tab]command

cronの再起動

cron関連のファイルを変更したら実行しよう

$ sudo service cron restart

cronの状態を確認

$ sudo service cron status

cronの実行履歴を確認

$  sudo journalctl -r -u cron.service
1
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
1
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?