【问题标题】:execute conky with a cron job and bash使用 cron 作业和 bash 执行 conky
【发布时间】:2010-12-21 13:41:56
【问题描述】:

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

谢谢

【问题讨论】:

    标签: bash cron conky


    【解决方案1】:

    我觉得应该是的

    export DISPLAY=:0
    

    但那不适合

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

    但你可以把它改成

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

    【讨论】:

    • 太棒了!有用。你能解释一下它的作用吗,因为我在论坛上找到了这个块,但我不明白它的作用
    • 它导出文件中不是注释的每一行 ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0 并且它被使用"找到 D-Bus 会话总线”。我的猜测是 conky 需要一个 dbus 会话来更新背景图像。
    【解决方案2】:

    你错过了一个“:”:

    export DISPLAY=:0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 2015-06-14
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      相关资源
      最近更新 更多