
我想定期從包含圖片的資料夾中隨機更改壁紙。我使用了程式“feh”並用 bash 編寫了一個小腳本,名為壁紙腳本.sh:
#!/bin/bash
files=(/torellino/Dropbox/Dropbox/Sfondi/*)
feh --bg-scale ${files[RANDOM % ${#files[@]}]}
當我在終端上使用該腳本時,它可以工作並且壁紙會隨機更改。為了使流程自動化並讓腳本每隔幾分鐘執行一次,我決定使用 systemd 計時器。所以我創建了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 ,我得到了這個:
“須藤journalctl -u壁紙.服務”
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。
您的輸出表明feh
無法開啟 X 伺服器。您應該在中設定幾個值wallpaper.server
User=
將其設定為您要為其設定壁紙的使用者。
Environment=DISPLAY=:0
需要進入顯示部分。 這個帖子解釋了為什麼兩者都需要。