对于我在 bash 中的脚本,如果它没有运行,我想开始 conky 并选择一个随机壁纸
#! /bin/bash
## dependances : randomize-lines
# otherwise wont work with cron
export DISPLAY=0
while read line ; do
echo $line | grep -vqe "^#"
if [ $? -eq 0 ]; then export $line; fi
done < ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-$DISPLAY
# random background
pathToImage="$HOME/Images/wallpaper/"
img="`find $pathToImage -name \*.jpg | rl | tail -n 1`"
/usr/bin/gconftool -t str -s /desktop/gnome/background/picture_filename $img
# test if conky is running
if ps ax | grep -v grep | grep conky > /dev/null
then
echo "conky running"
else
echo "conky is not running"
conky
fi
如果我尝试在终端中运行脚本
$ ~/script/wallpaper/random-background.sh
conky is not running
Conky: can't open display: 0
如果我将测试放在 DISPLAY=0 之前,它将在终端中工作,但不适用于 cron
谢谢你