1

I'm trying to run a shell file on python:

mongod --config /opt/mongodb/mongod.conf

and call it on python:

subprocess.call(['bash', 'run.sh'])

but it says mongod : not found.

When I run it in the terminal it works.

How can I fix this?

2 Answers 2

2

You don't need to use bash. Just run it as a normal script as you do in terminal:

import subprocess
subprocess.call(['./run.sh'])

Also it seems that mongod is not in your system environment path so you need to add absolute path of mongod to your run.sh:

#!/bin/bash
/opt/mongodb-linux-x86_64-ubuntu1404-3.0.6/bin/mongod --config /opt/mongodb/mongod.conf
Sign up to request clarification or add additional context in comments.

4 Comments

OS [ERRno 2] no such file file or directory
@Are you running the python script in the same directory of run.sh? Try to use subprocess.call(['sh', '<abs path to your run.sh>']).
I'm thinking that maybe mongod is not in your python env. Try to edit your run.sh and use the absolute path of mongod you can find it with whereis mongod.
Thanks i edit run.sh to /opt/mongodb-linux-x86_64-ubuntu1404-3.0.6/bin/mongod --config /opt/mongodb/mongod.conf and it work
1

try :

import os
os.system('bash run.sh')

update command to :

 #!/bin/sh
 /usr/bin/mongod --quiet --config /opt/mongodb/mongod.conf

1 Comment

i already update to /opt/mongodb-linux-x86_64-ubuntu1404-3.0.6/bin/mongod --config /opt/mongodb/mongod.conf and it work . Thanks .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.