0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[RaspberryPi] 定期実行方法 [Linux]

0
Last updated at Posted at 2026-03-15

cron設定の手順

① cron編集を開く

crontab -e

② 1行追加する

例:毎日 6:10 に main.py 実行

10 6 * * * cd /home/pi/raspi-epaper-dashboard && /usr/bin/python3 main.py

③ 保存

nano の場合

Ctrl + O 保存
Enter   確定
Ctrl + X 終了

cronの書式

分 時 日 月 曜日 コマンド

例

10 6 * * * コマンド (毎日 6:10 にコマンド実行)

よく使う例

用途 設定
毎日6:10 10 6 * * *
毎時間 0 * * * *
5分ごと */5 * * * *
1分ごと(テスト) * * * * *

設定確認

現在のcron一覧

crontab -l

トラブル対策

ログ残す

10 6 * * * cd /home/pi/raspi-epaper-dashboard && /usr/bin/python3 main.py >> /home/pi/dashboard.log 2>&1

2>&1について

番号 名前 内容
1 標準出力 (stdout) printなど通常メッセージ
2 標準エラー (stderr) エラーや例外

2>&1がない場合
標準出力(コード内のprint文など)はlogに出力されるが、エラーなどは出力されない

その為
その内容のstderr(2)をstdout(1)と合わせて出力するという意味が2>&1

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?