开发者

execute conky with a cron job and bash

for my script in bash, I'd like to start conky if it's not running and pick a random wallpaper

#! /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

if I try to run the script wit开发者_StackOverflowhin a terminal

$ ~/script/wallpaper/random-background.sh 
conky is not running
Conky: can't open display: 0

if I put the test before the DISPLAY=0, it'll works in a terminal but not with cron

thank you


I think that should be

export DISPLAY=:0

but that won't work for

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

but you could change that to

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


You missed a ":":

export DISPLAY=:0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜