Python Forum
subprocess Popen not working via crontab
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subprocess Popen not working via crontab
#1
Hey All,

Okay , I'm gonna admit this issue has me completely stumped and i'm at my wits end.

Below is the code that has been troubling me and i have tried all the things i know or could have googled.

session = Popen(['dgmgrl','username/password@dbname','stop observer', '-logfile', '/u01/app/oracle/broker/fsfo_mydg.log'],stdout=PIPE, stderr=PIPE, cwd=r'/u01/app/oracle/product/11.2.0/db1/bin/')
output,error = session.communicate()
if session.returncode != 0:
    raise RuntimeError("broker command failed with %s stdout %r stderr %r" % (session.returncode, output, error))
else:
    print >> file, "The stdout is :\n %s" % output
    file.flush()
So while trying to execute above directly on the terminal , it executes perfectly , But it simply does not runs and throws below error when scheduled to run from crontab.

Error:
OSError >  2 OSError >  No such file or directory OSError >  None
or 

Error:
RuntimeError >  broker command failed with -11 stdout '' stderr '' Successfully sent email at 2017-03-15 09:32:10.226847
and i have tried all combinations of command formatting.

Please help.

Regards,
Nitin
Reply
#2
I assume things in crontab are executed with a very specific user and environment, and the PATH can be different from what you have in a plain user session. So for a start I would give the full path to the executable, but this could not be sufficient.

As an experiment, write a Python script that reports the executing user id, the working directory and dumps the environment variables and have it execute from crontab.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
(Mar-15-2017, 09:37 PM)Ofnuts Wrote: I assume things in crontab are executed with a very specific user and environment, and the PATH can be different from what you have in a plain user session. So for a start I would give the full path to the executable, but this could not be sufficient.

As an experiment, write a Python script that reports the executing user id, the working directory and dumps the environment variables and have it execute from crontab.

Thanks for reply Ofnust,

I was able to solve it yesterday but due to deadlines could not post an update.

You are right , the issue was because of an environment variable needed by oracle utilities.

below is the code which solved it.

session = Popen([r'/u01/app/oracle/product/11.2.0/db1/bin/dgmgrl','username/password@dbname','stop observer', '-logfile', '/u01/app/oracle/broker/fsfo_mydg.log'],stdout=PIPE, stderr=PIPE, env=dict(os.environ, ORACLE_HOME="/u01/app/oracle/product/11.2.0/db1"))
Regards,
Nitin
Reply
#4
Thanks for coming back and letting us know what the problem was :)

I've had the same issue before (...more than once). Cron doesn't have any environment values set, so you need to use absolute paths, and the user and user group are different, so if you do any file reading/writing, the files you touch need pretty promiscuous permissions.
Reply
#5
(Mar-17-2017, 07:27 PM)nilamo Wrote: Thanks for coming back and letting us know what the problem was :)

I've had the same issue before (...more than once).  Cron doesn't have any environment values set, so you need to use absolute paths, and the user and user group are different, so if you do any file reading/writing, the files you touch need pretty promiscuous permissions.


The thing is i couldn't understand what " -11 " exit code represents , Yhg1s from python irc forum replied back that -11 is exit code for segmentation fault.

Then it became clear what the issue is. For oracle binaries to work ORALCE_HOME needs to be set , if it is not set i have seen segmentation fault issue.

Regards,
Nitin
Reply
#6
...oracle segfaults if environment variables aren't set? Yeah, THAT'S safe lol
Reply
#7
Despite its prices, corporate software is full of silly/innervating bugs like this, because the people who make the purchase decisions aren't those who use it so there is little incentive to fix them. IT operations people put up with a lot of crap.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#8
Indeed. When I was fresh from university I had opportunity to watch a tender for some simulation software (odd financial product).  Original request was for simulation, on way through higher management they added support for planning and accounting (with same weights). And at the end they bought only one offered software that couldn't simulate at all, but had nice planning and accounting. It was something like million $ for four year licence and another million for four year support and it was almost never used...
Reply
#9
My day job is basically building reports that are 100% top priority that need to be done right now, that people are surprised they didn't already have. They use it for maybe a week, and then look at it maybe once a month afterwards.

I get the same handful of requests every threeish months, so at least now I can just give them a url to go to and save myself some time.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding subprocess.Popen Pedroski55 6 388 May-12-2024, 10:46 AM
Last Post: Pedroski55
Information subprocess.Popen() suddenly giving me grief? davecotter 3 733 Dec-13-2023, 10:49 PM
Last Post: davecotter
  Use subprocess.Popen and time.sleep chucky831 2 2,014 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  Architecture question for website with python crontab script rockie12us 1 1,785 Aug-09-2021, 10:07 AM
Last Post: Larz60+
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,615 May-07-2021, 03:26 PM
Last Post: herwin
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 3,755 May-04-2021, 08:58 PM
Last Post: liudr
  disable subprocess.popen prompt echo paul18fr 1 2,091 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  how to pass the interactive string to Popen subprocess maiya 1 1,936 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  How to get program output from subprocess.Popen? glestwid 1 2,429 Aug-19-2020, 05:44 AM
Last Post: buran
  python os.popen is not working for wait method elenaflorence87 0 2,051 Jul-22-2020, 12:56 PM
Last Post: elenaflorence87

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020