Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Have script that runs perfectly when i just run ./grabJob.py through cron it seams to run but when it get to the popen it stops or throws error.
If run just ./grabJob.py it works ok and outputs
Code:
en:/var/www/apache2-default# ./grabJob.py
Grabbing Jobs
running create
Jobs runnning....
Creating environment ckortenhorst1
/usr/bin/xen-create-image --hostname=ckortenhorst1 --ip=192.168.0.111
DONE
./grabJob.py
Code:
# RUN all the Create ENVIRONMNET commands here
run="/usr/bin/xen-create-image --hostname=%s --ip=%s" % (hostname, ipadd[0])
print run;
try:
fs=os.popen(run)
for file in fs:
error = error + file
Through cron it does not work through bash it does work.
Can anyone help
found that crons env is different than bash but not sure how to change this
Does it run at all? Does it give you an error message? What's the first line of your python script (the one that says how to run it, i.e. "#!/usr/bin/env python")?
It's probably a path issue, assuming you can get a cron to run at all. You can get a cron running, right? Like, if you make a cron that echos `date` to some file every minute, it works, yes?
If I remember correctly, there is another possible issue: the timing of events in the script.
When run in the terminal, the script gets to fs=os.popen(run) and waits until that part is complete before moving on to for file in fs:
When run as a background process, it may not wait as it would in a terminal. So, if you know how long it takes the fs=os.popen(run) to run, try putting a sleep in there for the appropriate amount of time (before the for loop), then try it again as a cron job to see if it runs.
I could be off base, but I seem to remember something to that effect from my Unix class a few years ago.
You can also test the program via the batch command. The batch command executes commands just like cron – with no terminal connected, but at a later time when system load levels permit. Using batch saves you the trouble of modifying crontab for just a test-run.
Example run:
Code:
$> batch
warning: commands will be executed using /bin/sh
at> touch /tmp/now~
at> ^D
$> ls -l /tmp/now~
-rw-r--r-- 1 user group 0 2007-11-15 21:26 /tmp/now~
$>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.