开发者

Run cronjob as user to change desktop background in Ubuntu [closed]

开发者 https://www.devze.com 2022-12-18 14:49 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 9 years ago.

Improve this question

I am trying to run this script which changes my desktops background to a random picture in a directory. It works from the command line, and the cronjob gets run (added output and it gets spit out to a log file), but I can't get it to change my background. Here's my current line (set to run every minute for testing).

01 * * * * username /home/username/.wallpa开发者_运维百科pers/flip.sh

Any Ideas?


bug: https://bugs.launchpad.net/ubuntu/+source/gconf/+bug/285937

my version:

#!/bin/bash

# Script to randomly set Background from files in a directory

# Directory Containing Pictures
DIR=/home/lucas/studio/art/images/tapety
LOG=/home/lucas/tapeta.log

# Command to Select a random file from directory
PIC="$(
for p in [jJ][pP][gG] [pP][nN][gG] [sS][vV][gG] ; do
 ls $DIR/*.$p
done | shuf -n1
)"
# Command to set Background Image
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then
 # this is because of gconftool bug in cron
 TMP=~/.dbus/session-bus
 export $(grep -h DBUS_SESSION_BUS_ADDRESS= $TMP/$(ls -1t $TMP | head -n 1))
 echo $DBUS_SESSION_BUS_ADDRESS >> $LOG
fi

gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$PIC"

and it's works on Fedora 12


cron scripts have no access to the user's display. Use something like wallpapoz instead.


01 * * * * /home/username/.wallpapers/flip.sh

means it runs every hour, if you want to run it every minute, it has to be

*/1 * * * * /home/username/.wallpapers/flip.sh

The syntax is also described on Wikipedia.

Or use GNOME Schedule as proposed.

Is flip.sh executable?

Edit: And true, the username has to be removed (in the system wide cron file, see silent's comment).Maybe this CronHowto also helps.



I works great on my ubuntu hardy.

#!/bin/bash

# Script to change desktop background randomly every 5 mins through cronjob

FIND=/usr/bin/find
GCONFTOOL2=/usr/bin/gconftool-2
IMG_DIR=/home/username/Pictures/wallpapers

FILES=( `$FIND $IMG_DIR -iname '*.jpg'` )
TOTAL=${#FILES[@]}

# Select random number from 0 to $TOTAL
let INDEX=$RANDOM%TOTAL

$GCONFTOOL2 --type string --set /desktop/gnome/background/picture_filename "${FILES[${INDEX}]}"
$GCONFTOOL2 --type string --set /desktop/gnome/background/picture_options "centered"



Run it through cronjobs:

05 * * * * /home/username/scripts/wallpaper_switcher.sh

0

精彩评论

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

关注公众号