About
Community
Bad Ideas
Drugs
Ego
Erotica
Fringe
Society
Technology
register | bbs | search | rss | faq | about
meet up | add to del.icio.us | digg it
Go Back   Community > Technology > Everything *NIX
Register FAQ Members List Calendar Today's Posts

Everything *NIX This is a general forum about all forms of *nix. Post your ideas and thoughts on this wonderful OS family. Talk about your personal favorite flavor of *nix and why you think it's so much better than the others. Anything pertaining to *nix and *nix administration should be posted here.

Reply
 
Thread Tools Display Modes
  #1   Add RAOVQ to your ignore list  
Old 2008-06-08, 16:57
RAOVQ RAOVQ is offline
Regular
 
the happy land of australia
Default script being unhappy.

Inspired by the other thread, i found a script to change the background every hour.

The thing is, it doesn't work from cron.hourly. If i run it from the shell it works nicely, but doesn't i run it from sudo. i know its running because if put an echo in there it appears, but the background doesn't change. ive given it 700, 755 and 777 permissions, all with the same result.

heres the script,
Code:
#!/bin/bash

# script: change_backgrounds.sh - bash version

# version 2007.3.7

# description: randomly replace gnome background with one from a directory

# credits: David Loschiavo [http://www.djlosch.com], Steven Van Ingelgem

# license: GPL





bg_path=/usr/autoBG

extensions="jpg png gif jpeg JPG GIF PNG"

temp_bg_list=/tmp/bg_change_list



rm -f $temp_bg_list



for extension in $extensions

do

	find $bg_path -iregex ".*.$extension" >> "$temp_bg_list"

done



cnt=`wc -l "$temp_bg_list" | cut -f1 -d" "`

all_bgs=`echo \`expr $RANDOM % $cnt\``



selected_bg=`head -n$all_bgs "$temp_bg_list" | tail -n1`



logger "Changed desktop to: $selected_bg"



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

exit 0
from what i gather, it is trying to work but the path /usr/autoBG is not working as it should when run by root. im not experienced enough with this to figure it out, so any advice would be great.
Reply With Quote
  #2   Add Prometheum to your ignore list  
Old 2008-06-08, 18:16
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: script being unhappy.

Why are you running it as root? You should probably change the directory that it searches to the one that the files are actually in.

Also, I don't know if gconf would be nice with root. You might be chaning root's gconf hive.
Reply With Quote
  #3   Add 01 to your ignore list  
Old 2008-06-08, 23:17
01 01 is offline
Regular
 
Default Re: script being unhappy.

Listen to Prometheum, don't run it as root and put the images in the same directory (~/raovq, for example).
That should alleviate any permission issues.
GConf is userland specific. So when you sudo you are chain loading gconf as root.

I bet if you logged in as root (if your distro allows), you'd find you're changing root's background.
Reply With Quote
  #4   Add RAOVQ to your ignore list  
Old 2008-06-09, 03:53
RAOVQ RAOVQ is offline
Regular
 
the happy land of australia
Default Re: script being unhappy.

allright, i understand the problem, it is changing a desktop on root. i havent logged in to test it, but i added
echo "Changed desktop to: $selected_bg"

and spits out what i expect, although the background doesn't change unless i run it from my normal user shell.

i assumed that when the system runs the cron.hourly jobs it does so from root or something?

but i don't know how to fix it.
Reply With Quote
  #5   Add RAOVQ to your ignore list  
Old 2008-06-09, 08:55
RAOVQ RAOVQ is offline
Regular
 
the happy land of australia
Default Re: script being unhappy.

i fiddled around with trying to switch users before i run the last command, something like
su raovq -c gconftool.... worked, but asked for a password each time. running in root didn't really help. chown root didn't make a difference.

so i gave up and threw the script into /usr/bin/, and used crontab to call it every hour. without any adjustments it works perfectly.

im not sure why one works and not the other, but it's all good now. ive learnt to not touch any of the cron.time folders, and stick to crontab. bit of a shame though.

edit: the background changed on the hour, as well as 17 past. i didn't delete the original cron.hourly script yet, so i guess i fixed it but the test failed. i guess ill find out in 33 minutes if it works properly.

edit2: it works properly now. the line ended up being
su raovq -c "gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$selected_bg""

i had to make it owned by root to work without needing a password. my faith in cron.time is restored (if anyone is still following).

Last edited by RAOVQ; 2008-06-09 at 10:23.
Reply With Quote
  #6   Add Prometheum to your ignore list  
Old 2008-06-09, 17:20
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: script being unhappy.

Quote:
Originally Posted by RAOVQ View Post
i fiddled around with trying to switch users before i run the last command, something like
su raovq -c gconftool.... worked, but asked for a password each time. running in root didn't really help. chown root didn't make a difference.

so i gave up and threw the script into /usr/bin/, and used crontab to call it every hour. without any adjustments it works perfectly.

im not sure why one works and not the other, but it's all good now. ive learnt to not touch any of the cron.time folders, and stick to crontab. bit of a shame though.

edit: the background changed on the hour, as well as 17 past. i didn't delete the original cron.hourly script yet, so i guess i fixed it but the test failed. i guess ill find out in 33 minutes if it works properly.

edit2: it works properly now. the line ended up being
su raovq -c "gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$selected_bg""

i had to make it owned by root to work without needing a password. my faith in cron.time is restored (if anyone is still following).
Ah, the wonder of Freedom: you can make things work.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

 
To the best of our knowledge, the text on this page may be freely reproduced and distributed.
 

totse.com certificate signatures
 
 
About | Community | Bad Ideas | Drugs | Ego | Erotica | Fringe | Society | Technology
Hot Topics