1

对于我在 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

谢谢你

4

2 回答 2

4

我认为应该是

export DISPLAY=:0

但这不起作用

~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-$DISPLAY

但你可以把它改成

~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
于 2009-11-30T08:38:06.010 回答
2

你错过了一个“:”:

export DISPLAY=:0
于 2009-11-30T08:38:46.740 回答