システムを起動してから30分ごとにスクリプトを実行したいと思います。 cronを使用できることは知っていますが、この機能を頻繁に使用する予定はないため、systemdで試してみたいと思います。
これまでのところ、何かを一度だけ実行できる単調なタイマーしか見つかりませんでした(少なくとも私はそう思います)。 foo.timer
はどうですか? および[email protected]
起動/システム起動から30分ごとに何かを実行したい場合のように見えますか?
[メール保護]
[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... ???
承認された回答:
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
その後、コマンドsystemctl daemon-reload
を使用してsystemdをリロードします systemctl start test.timer
でタイマーを開始します 、またはデフォルトで有効にします(systemctl enable test.timer
。
1.sh
のコンテンツをテストする
#!/bin/bash
echo `date` >> /tmp/2
そして、使用可能なすべてのタイマーをチェックするコマンド:systemctl list-timers --all
プロジェクトページの詳細情報とArchLinuxページの例