NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
PatrikL
Oct 12, 2011Aspirant
Not getting cron to work
I've tried to get a script (importing torrent files from rss) executed once an hour by simply placing it in cron.hourly but nothing whatsoever happens. The script executes well manually when I'm logged in as root and the file permissions are set to exactly the same as the files in cron.daily (since there were none in cron.hourly) but doesnt seem to run. Or does and I havent found the log that says that something went wrong?
Yesterday I moved it to cron.daily to see if that works better but no luck...
Any idea to what I am doing wrong? Do I need to register my script file somewhere as well as putting it into one of the cron directories?
Cheers
Edit: This is on a ReadyNas Ultra 2, bought a few weeks ago and updated to the latest firmware since then
Yesterday I moved it to cron.daily to see if that works better but no luck...
Any idea to what I am doing wrong? Do I need to register my script file somewhere as well as putting it into one of the cron directories?
Cheers
Edit: This is on a ReadyNas Ultra 2, bought a few weeks ago and updated to the latest firmware since then
25 Replies
Replies have been turned off for this discussion
- PatrikLAspirant
sphardy wrote: 2. They will be run under a standard bourne shell (/bin/sh) so be sure that your script runs fine under that (standard login shell for the root user is bash, not bourne shell)
And that is the reason! I havent solved it yet but running it using /bin/sh gives me plenty or errors. It seems to be the case that the line telling it my script is python isnt correct.
My script starts with:#!/usr/bin/python
import feedparser
import urllib2
import time
import datetime
And the first error I am getting is that "import" on line 2 isnt recoqnized. I'll google around a bit to see how to change it unless you know by heart? - PatrikLAspirantAlso tried starting with:
#!/usr/bin/ev python
Since I found that on several sites but getting the same errors:
/etc/cron.hourly/import_rss.py: line 3: import: command not found
/etc/cron.hourly/import_rss.py: line 4: import: command not found
/etc/cron.hourly/import_rss.py: line 5: import: command not found
/etc/cron.hourly/import_rss.py: line 6: import: command not found
/etc/cron.hourly/import_rss.py: line 8: DownloadPath: command not found
/etc/cron.hourly/import_rss.py: line 9: DownloadLog: command not found
/etc/cron.hourly/import_rss.py: line 10: FeedUrl: command not found
/etc/cron.hourly/import_rss.py: line 11: LogPath: command not found
/etc/cron.hourly/import_rss.py: line 13: syntax error near unexpected token `('
/etc/cron.hourly/import_rss.py: line 13: `def is_downloaded(link):' - sphardy1ApprenticeDoes the script run properly if you execute it as /usr/bin/python <script> ??
If so, might be easier to just create your own cron schedule (crontab -e) and explicitly define the command to be run - PatrikLAspirant
sphardy wrote: Does the script run properly if you execute it as /usr/bin/python <script> ??
If so, might be easier to just create your own cron schedule (crontab -e) and explicitly define the command to be run
Yes it does so I'll try that. thanks - sphardy1Apprentice
PatrikL wrote: Also tried starting with: #!/usr/bin/ev python
Assume there's a typo there?#!/usr/bin/env python
Also maybe you could create another script in cron.hourly to workaround the problem:
#!/bin/sh
/usr/bin/python /path/to/my/python/script.py - PatrikLAspirantYeah typo, should have copy/pasted.
And about the second script, thats exactly what I did just before I saw your post and it seems to work (well running it from sh anyway does). I'll stick to this for now assuming it works but I'll see that in 30 min or so.
crontab -e didnt work but I'm guessing it's just a question of an editor not beeing set.
Thanks for all the help! - WhoCares_MentorSorry to interrupt once again but I guess the inital problem is the usage of the /usr/bin/env hack. That's because by default a cron shell will get passed an almost empty environment (which is why in the general crontab the PATH variable is set explicitly). Depending on the version of cron used it is not guaranteed that the information contained in the general crontab file is passed to jobs that are run from the cron.d directory.
So running #!/usr/bin/env python will most likely fail because there is no PATH to be searched, resulting in the script being interpreted by /bin/sh. And that in turn leads to the error with unknown import command. To fix this and to be able to run python scripts directly without having to write a wrapper all the time you could either replace the #!/usr/bin/env python with just #!/usr/bin/python or add a PATH="whatever path configuration you need" to the head of the cronjob definition file.
-Stefan - sphardy1Apprentice
replace the #!/usr/bin/env python with just #!/usr/bin/python
But #!/usr/bin/python is what the OP tried first and is failing - and the use of #!/usr/bin/env python was the workaround the OP then tried afterwards
It does not appear to be path/environment related as calling the script from a bourne shell works fine, so it seems to be that #!/usr/bin/python is not being interpreted properly - PatrikLAspirant
WhoCares? wrote: Sorry to interrupt once again but I guess the inital problem is the usage of the /usr/bin/env hack. That's because by default a cron shell will get passed an almost empty environment (which is why in the general crontab the PATH variable is set explicitly). Depending on the version of cron used it is not guaranteed that the information contained in the general crontab file is passed to jobs that are run from the cron.d directory.
So running #!/usr/bin/env python will most likely fail because there is no PATH to be searched, resulting in the script being interpreted by /bin/sh. And that in turn leads to the error with unknown import command. To fix this and to be able to run python scripts directly without having to write a wrapper all the time you could either replace the #!/usr/bin/env python with just #!/usr/bin/python or add a PATH="whatever path configuration you need" to the head of the cronjob definition file.
-Stefan
Sorry Stefan I never wrote how my original script started and that was with:
#!/usr/bin/python
That never worked either and the error messages indicates that that line wasnt understod.
Despite the script now working when executed from /bin/sh, cron doesnt seem to run it or if it does and it fails, nothing is logged... I'll have some further looks later tonight but as I said earlier Transmission constantly crashing on smoe torrents is a bigger issue for me now anyway :-( - WhoCares_MentorYou could try ruTorrent if you want. If so, just drop me a note ;)
-Stefan
Related Content
NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology!
Join Us!