使用crontab使用pcmanfm更改墙纸

lsc*_*eal 4 bash crontab pcmanfm

我制作了一个简单的bash脚本,该脚本使用pcmanfm从我的壁纸目录中更改了一张随机图片的壁纸。就像这样:

#!/bin/bash

pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"
Run Code Online (Sandbox Code Playgroud)

我会自动想要它,所以您将脚本放在crontab上。但是,当crontab调用它时,它没有任何作用。我的脚本怎么了?我该如何解决?

谢谢

Rad*_*anu 5

当设置为cron作业时,该脚本将给您X11授权错误。为了防止这种情况,只需在脚本中添加export DISPLAY=:0和(更改用户名):export XAUTHORITY=/home/username/.Xauthorityusername

#!/bin/bash

export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority   #change `username` with your user name

pcmanfm -w "$(find /home/likewise-open/MAPS/lucas.cardeal/Pictures/Wallpapers -type f | shuf -n1)"
Run Code Online (Sandbox Code Playgroud)

附录:更新导致以上脚本在Lubuntu 16.04及更高版本中损坏。请参阅此stackoverflow答案/sf/answers/3238132201/,以获取需要在脚本中指定的其他环境变量。