I am trying to start a mongodb using a cronjob+shell-script combo.

In the shell, mongoDB starts when I enter $ mongod, however my executable shell script fails with mongod: command not found. I then tried ./mongodb, and the error was No such file or directory.

It seems like it might be some sort of path problem (FWIW I have installed mongoDB using homebrew) but I'm not sure where to look to fix it.

How might I start a mongoDB from a shell script?

  • 1
    Do you know the full directory path to the mongod binary? If the answer is no, the following command should work: "sudo find / -name mongod" – John in Ohio Mar 10 '13 at 6:54
  • +1. yes, which mongod returns a full path -- and substituting that in my script fixes the problem. make it a full answer and i'll accept it. thanks – ricardo Mar 10 '13 at 8:18

You can determine the full directory path to the mongod binary by running the following command:

"sudo find / -name mongod"

Substitute the full path and filename of the binary instead of making a relative call to the binary as you were in the past in your script and you should see the results you're looking for.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.