用cron job和bash执行conky

时间:2009-11-30 08:31:12

标签: bash cron conky

对于我在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一起工作

谢谢

2 个答案:

答案 0 :(得分:2)

我认为那应该是

export DISPLAY=:0

但这不适用于

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

但您可以将其更改为

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

答案 1 :(得分:1)

你错过了一个“:”:

export DISPLAY=:0