システム起動後30分ごとにスクリプトを実行したいと思います。 cronを使用できることを知っていますが、この機能を頻繁に使用する予定はないので、systemdで試したいと思いました。
これまで、私は何かを一度だけ実行できる単調なタイマーだけを見つけました(少なくとも私の考えではそうです)。起動/システム起動から30分ごとに何かをしたい場合とはどうなりますかfoo.timer
?[email protected]
[Unit]
Description=run foo
Wants=foo.timer
[Service]
User=%I
Type=simple
ExecStart=/bin/bash /home/user/script.sh
foo.timer
[Unit]
Description=run foo
[Timer]
where I am stuck... ???
ベストアンサー1
2つのファイルを生成する必要があります。 1つはサービス用、もう1つは同じ名前のタイマー用です。
例:
/etc/systemd/system/test.service
[Unit]
Description=test job
[Service]
Type=oneshot
ExecStart=/bin/bash /tmp/1.sh
/etc/systemd/system/test.timer
[Unit]
Description=test
[Timer]
OnUnitActiveSec=10s
OnBootSec=10s
[Install]
WantedBy=timers.target
次に、コマンドを使用してsystemdを再ロードsystemctl daemon-reload
し、タイマーを起動するsystemctl start test.timer
か、デフォルトで有効にします(systemctl enable test.timer
)。
テスト内容は1.sh
#!/bin/bash
echo `date` >> /tmp/2
そして、このコマンドは利用可能なすべてのタイマーをチェックします。
systemctl list-timers --all
プロジェクトの詳細ページそしての例アーチLinuxページ