systemdタイマーを使用してbashスクリプトをスケジュールする

systemdタイマーを使用してbashスクリプトをスケジュールする

写真を含むフォルダで定期的に壁紙をランダムに変更したいと思います。私は "feh"というプログラムを使用し、bashで次のような小さなスクリプトを書いた。wallpaperscript.sh:

#!/bin/bash
files=(/torellino/Dropbox/Dropbox/Sfondi/*)
feh --bg-scale ${files[RANDOM % ${#files[@]}]}

端末でスクリプトを使用すると動作し、壁紙がランダムに変わります。プロセスを自動化し、スクリプトが数分ごとに実行されるようにシステムタイマーを使用することにしました。そのため、2つのファイルを作成して/etc/systemd/system/に入れました。

壁紙.サービス:

[Unit]
Description=Call wallpaperscript.sh and change the wallapaper

[Service]
ExecStart="/etc/systemd/system/wallpaperscript.sh"

そして壁紙。タイマー:

[Unit]
Description=Runs wallpaperscript every 10 minutes

[Timer]
# Time to wait after booting before we run first time
OnBootSec=1min
# Time between running each consecutive time
OnUnitActiveSec=10min
Unit=wallpaper.service

[Install]
WantedBy=multi-user.target

実際に私が自分で作ったのではなく、どこかで発見したのです。とにかくwallpaper.timerを有効にして起動しましたが、動作しません。 「systemctl status wall.timer」をチェックすると、実際にタイマーが動作していることがわかります。

● wallpaper.timer - Runs wallpaperscript every 10 minutes
Loaded: loaded (/etc/systemd/system/wallpaper.timer; enabled; vendor preset: disabled)
Active: active (waiting) since Fri 2018-06-01 19:42:40 CEST; 16min ago
Trigger: Fri 2018-06-01 20:03:47 CEST; 4min 14s left

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

反対側のwallpaper.serviceでエラーが発生します。

● wallpaper.service - Call wallpaperscript.sh and change the wallapaper
Loaded: loaded (/etc/systemd/system/wallpaper.service; static; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2018-06-01 19:53:47 CEST; 7min ago
Process: 919 ExecStart=/etc/systemd/system/wallpaperscript.sh (code=exited, status=2)
Main PID: 919 (code=exited, status=2)

解決策を見つけましたが、何も見つかりませんでした。ところで、systemdを初めて使用して問題を直接把握することはできません。

これが役立つ場合は、Arch-linuxとi3を使用しています。

私もwall.serviceのsderrを得て、これを得ました:

"sudoジャーナルctl -u wallpaper.service"

giu 01 19:43:38 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 19:43:39 placobravo wallpaperscript.sh[452]: feh WARNING: You have no HOME, cannot read configuration
giu 01 19:43:39 placobravo wallpaperscript.sh[452]: feh ERROR: Can't open X display. It *is* running, yeah?
giu 01 19:43:39 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
giu 01 19:43:39 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.
giu 01 19:53:47 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 19:53:47 placobravo wallpaperscript.sh[919]: feh WARNING: You have no HOME, cannot read configuration
giu 01 19:53:47 placobravo wallpaperscript.sh[919]: feh ERROR: Can't open X display. It *is* running, yeah?
giu 01 19:53:47 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
giu 01 19:53:47 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.
giu 01 20:04:47 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 20:04:47 placobravo wallpaperscript.sh[1108]: feh WARNING: You have no HOME, cannot read configuration
giu 01 20:04:47 placobravo wallpaperscript.sh[1108]: feh ERROR: Can't open X display. It *is* running, yeah?
giu 01 20:04:47 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
giu 01 20:04:47 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.
giu 01 20:15:47 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 20:15:47 placobravo wallpaperscript.sh[1343]: feh WARNING: You have no HOME, cannot read configuration
giu 01 20:15:47 placobravo wallpaperscript.sh[1343]: feh WARNING: /torellino/Dropbox/Dropbox/Sfondi/the does not exist - skipping
giu 01 20:15:47 placobravo wallpaperscript.sh[1343]: feh WARNING: witcher3.jpg does not exist - skipping
giu 01 20:15:47 placobravo wallpaperscript.sh[1343]: feh: No loadable images specified.
giu 01 20:15:47 placobravo wallpaperscript.sh[1343]: See 'feh --help' or 'man feh' for detailed usage information
giu 01 20:15:47 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=1/FAILURE
giu 01 20:15:47 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.
giu 01 20:26:47 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 20:26:47 placobravo wallpaperscript.sh[1388]: feh WARNING: You have no HOME, cannot read configuration
giu 01 20:26:47 placobravo wallpaperscript.sh[1388]: feh ERROR: Can't open X display. It *is* running, yeah?
giu 01 20:26:47 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
giu 01 20:26:47 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.
giu 01 20:37:47 placobravo systemd[1]: Started Call wallpaperscript.sh and change the wallapaper.
giu 01 20:37:47 placobravo wallpaperscript.sh[1579]: feh WARNING: You have no HOME, cannot read configuration
giu 01 20:37:47 placobravo wallpaperscript.sh[1579]: feh ERROR: Can't open X display. It *is* running, yeah?
giu 01 20:37:47 placobravo systemd[1]: wallpaper.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
giu 01 20:37:47 placobravo systemd[1]: wallpaper.service: Failed with result 'exit-code'.

私が知る限り、Jeff Schallerが指摘したように、fehはXにアクセスできないようです。この問題をどのように解決できるかを知っている人はいますか?

ベストアンサー1

StackExchangeへようこそ。

出力にfehXサーバーを開くことができないと表示されます。設定する必要があるいくつかの値がありますwallpaper.server

User=

壁紙を設定したいユーザーに設定します。

Environment=DISPLAY=:0

ディスプレイセクションに入る必要があります。 この投稿両方が必要な理由を説明します。

おすすめ記事