LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 03-04-2008, 02:36 PM   #1
namit
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 355

Rep: Reputation: 30
cron different form interactive


Hey just wondering could anyone help me

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


Code:
xen:~# diff intteractiv crons_env 
1,7c1,2
< TERM=xterm-color
< SHELL=/bin/bash
< SSH_CLIENT=192.168.10.140 49597 22
< SSH_TTY=/dev/pts/1
< USER=root
< MAIL=/var/mail/root
< PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
---
> SHELL=/bin/sh
> PATH=/usr/bin:/bin
10,11d4
< PS1=\h:\w\$ 
< SHLVL=1
13c6
< LS_OPTIONS=--color=auto
---
> SHLVL=2
15d7
< SSH_CONNECTION=192.168.10.140 49597 192.168.0.93 22
 
Old 03-04-2008, 03:13 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
As a test, try running it from a terminal, in background so that the terminal is immediately released back to you. Does it stil choke up?
 
Old 03-04-2008, 03:21 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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?
 
Old 03-04-2008, 03:48 PM   #4
namit
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 355

Original Poster
Rep: Reputation: 30
Yes sorry should have explained it does run upto the xen-create

first line is
#!/usr/bin/python

Yup cron is working no problem, can i just copy and post these environmnet variables into crontab -e?


SHELL=/bin/bash
USER=root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/root
LANG=en_IE.UTF-8
PS1=\h:\w\$
SHLVL=1
HOME=/root
LOGNAME=root

?
 
Old 03-04-2008, 04:38 PM   #5
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.
 
Old 03-04-2008, 09:12 PM   #6
namit
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 355

Original Poster
Rep: Reputation: 30
THANK you so so much just added this to crontab and works a treat.

xen:/var/www/apache2-default# crontab -e
# m h dom mon dow command
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


Thank you
 
Old 03-05-2008, 02:07 PM   #7
fvu
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
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~
$>
See also:
At and Batch - Red Hat Documentation


Freddy Vulto
http://fvue.nl
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to design interactive contact form for web page? bezdomny Linux - General 3 09-06-2007 10:03 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
bash script works when interactive, endless loop when started via cron dguy Linux - General 5 04-10-2006 11:39 AM
How to schedule *interactive* task with at or cron fast_rizwaan Linux - Newbie 4 09-09-2005 06:26 PM
Interactive website form help micro_sucks General 0 12-24-2003 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration