So this is a super weird issue. I have a python script that calls many bash commands via subprocess.call based on certain criteria. Now, the script runs just fine manually but when thrown into a cronjob it fails, BUT only when it gets to a certain part of the code. This part of the code runs a bstat and a bkill command on a user. I've tried using subprocess.call, subprocess.Popen, subprocess.check_output for these two commands and every time it reaches them, it hangs and does nothing. I then get this message in var/spool/mail/root

File "/root/Desktop/script.py", line 75, in <module>
    print subprocess.check_output(['bstat' '-q' 'viz' '-u' ,user,])
  File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I've tried: using absolute paths for EVERY command possible, changing directories to the directory of the script before running, calling /bin/python before running. I'm at a total loss. What's even more weird, is there are other subprocess.call commands that work just fine when calling a bash script but when it comes to those two commands it doesn't know what to do. Below is the first subprocess command that it hangs on:

print subprocess.check_output(['bstat' '-q' 'viz' '-u' ,user,])

1 Answer 1


The subprocess call is looking for the bstat or bkill programs in the $PATH... except there is not $PATH` in the cron environment. Specify the full path to those programs, even inside the Python script, and it should work.

  • So I've done a which bkill and which bstat command and put those full paths in the python script where I call those two commands. But I still get no such file or directory errors. Is there anywhere else I have to define the $PATH
    – Michael
    Jul 2, 2019 at 12:23
  • 1
    If the bkill and bstat programs are in turn scripts, they will likely need a sane environment, including a sane $PATH.
    – John
    Jul 2, 2019 at 12:33
  • LSF generally requires that the environment configuration in profile.lsf has been sourced before the CLI will work. Jul 3, 2019 at 17:35
  • @MichaelClosson answer is what worked for me
    – Michael
    Oct 2, 2019 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .