Fedora Linux Support Community & Resources Center
  #1  
Old 18th March 2012, 02:00 PM
manuelmarque Offline
Registered User
 
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5
linuxchrome
trouble with python script and cron

Hello all,

I've searched extensively in this forum and found no mention of a similar problem, so here goes: I have written a little Python script to randomly rotate my wallpaper (since GNOME 3 removed that ability). My first approach to it was quite silly, since I had put it running in a loop and of course that required a lot of CPU time.

Then I started looking at cron. I set up a simple call to the script (which is in my user home) every 2 minutes. Trouble is, I can see that crond effectively called it (I've been watching /var/log/cron for some time) but does not run it. (and yes, the script does run when I call it manually! )

I've tried putting it in the system's crontab (/etc/crontab) and the user's one, I've also tried to make root run the script instead of me (in case my user account is not authorised to run cronjobs...), and I even tried to disable SELinux to see if that help (it didn't).

Can you please give me a hand with this? Oh, and my machine is running the 64-bit version of Fedora 16. (no rawhide, just standard updates, I want to keep it as stable as possible...)

Best regards,
Manuel Marques
Reply With Quote
  #2  
Old 18th March 2012, 04:23 PM
Alberth5674764 Offline
Registered User
 
Join Date: Nov 2011
Posts: 35
linuxfirefox
Re: trouble with python script and cron

under cron, the environment is much less complete than a normal shell.
Use full paths everywhere, and remove any tilde (~) stuff.
Reply With Quote
  #3  
Old 18th March 2012, 04:24 PM
manuelmarque Offline
Registered User
 
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5
linuxchrome
Re: trouble with python script and cron

Quote:
Originally Posted by Alberth5674764 View Post
under cron, the environment is much less complete than a normal shell.
Use full paths everywhere, and remove any tilde (~) stuff.
Yeah, I did that, both within the script itself and the crontab - I only used absolute paths!

Thanks anyway
Reply With Quote
  #4  
Old 18th March 2012, 04:31 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,896
linuxfirefox
Re: trouble with python script and cron

The process the cron process runs does not have access to the display, and cannot put anything on it.

All it could do is replace the default background in the configuration files.

The only way you can reliably get it to work is to run in the same context as the gnome shell - however you find any "auto-start" capabilities.
Reply With Quote
  #5  
Old 18th March 2012, 05:15 PM
manuelmarque Offline
Registered User
 
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5
linuxchrome
Re: trouble with python script and cron

Quote:
Originally Posted by jpollard View Post
The process the cron process runs does not have access to the display, and cannot put anything on it.

All it could do is replace the default background in the configuration files.
So, you're saying that when I run the command-line gsettings tool within the script it won't actually access the DE settings? Because I can run it from a shell and it works...

---------- Post added at 03:15 PM ---------- Previous post was at 02:37 PM ----------

Haha, all it took was to supply the command with the correct display (prefix DISPLAY=:0.0) and it is now working perfectly!

See here: http://fuzzytolerance.info/rotating-...3-with-python/ (I had already checked this blog entry in order to script gnome-shell actions in Python, but forgot to read the comments... shame on me! )

Thanks for the tip, jpollard. One is always learning!
Reply With Quote
  #6  
Old 18th March 2012, 09:12 PM
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 6,118
linuxfirefox
Re: trouble with python script and cron

I still don't get why doing something in a loop once every couple minutes would use a lot of cpu time? The script would be sleeping nearly all the time and using nearly 0 cpu time.
Reply With Quote
  #7  
Old 18th March 2012, 11:22 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,896
linuxfirefox
Re: trouble with python script and cron

Quote:
Originally Posted by manuelmarque View Post
So, you're saying that when I run the command-line gsettings tool within the script it won't actually access the DE settings? Because I can run it from a shell and it works...

---------- Post added at 03:15 PM ---------- Previous post was at 02:37 PM ----------

Haha, all it took was to supply the command with the correct display (prefix DISPLAY=:0.0) and it is now working perfectly!

See here: http://fuzzytolerance.info/rotating-...3-with-python/ (I had already checked this blog entry in order to script gnome-shell actions in Python, but forgot to read the comments... shame on me! )
It all depends on who is logged in. If you are the only user then that will work.... some times - If you are not logged in you get errors. If someone else is logged in (or you as someone else) more errors.
Reply With Quote
  #8  
Old 19th March 2012, 12:03 AM
manuelmarque Offline
Registered User
 
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5
linuxchrome
Re: trouble with python script and cron

Quote:
Originally Posted by jpollard View Post
It all depends on who is logged in. If you are the only user then that will work.... some times - If you are not logged in you get errors. If someone else is logged in (or you as someone else) more errors.
OK, thanks for the tip! But since this is my personal computer in which I am the sole user (and I don't intend to run a graphical session as root) I think I won't run into further problems...

Regarding marko's post (I thought I had replied but the post is not here, something failed... :P) - I had initially set the script to do the timing by itself (every 45 minutes or so it would then run the function to rotate the wallpaper) but since I didn't know about the timer.sleep() function I did what every newbie would do: while True and everything inside the loop! (which is good if you're programming a microcontroller which will only do that little piece of code, but it is *not* OK for a daemon which we want to have the minimum possible impact on the system! :P)

Which was the main reason I switched to a cron-based solution and left the timing chores to the OS - a more clever solution, if you ask me!

---------- Post added at 10:03 PM ---------- Previous post was at 09:35 PM ----------

Quote:
Originally Posted by marko View Post
I think there are already gnome plugins and KDE plasma widgets that will do wallpaper rotation for you. That might be a good thing to look into also
Hmmm, I checked the main gnome extensions website and found nothing on that... and I'm not that huge fan of KDE, so I wouldn't go that way either (KDE _does_ have multiple image support for the wallpaper built-in, I think...).
Reply With Quote
Reply

Tags
cron, python, script, trouble

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cron script help Jamwa Programming & Packaging 4 7th June 2011 06:18 AM
bug in apt cron script? Adrian_Hands Using Fedora 0 24th December 2007 09:25 PM
I need a script or cron job that does ... Wiles Using Fedora 1 13th September 2007 03:37 PM
help with a cron script Pulsorock Using Fedora 1 10th July 2007 08:24 AM
/etc/cron.daily/yum.cron: Error: python-devel conflicts with python < 2.3.4-13.1 productive Servers & Networking 0 20th April 2005 09:51 PM


Current GMT-time: 21:46 (Thursday, 18-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Creek Side - Stockholm-Arlanda Airport (ARN) Travel Photos on Instagram - Marina of Koper Travel Photos - Te Whiti Park Instagram Photos - Texas State Fair Photos on Instagram