arbabk arbabk - 3 months ago 20
Bash Question

Bash script not executing mongod command

I have a simple bash script to run mongodb:

#!/bin/bash
sudo mongod --dbpath data/db
echo "Mongo is running!"


In the terminal, I execute:


. ./mongo.sh


I am sure that the directory is correct and that I have already CHMOD my permissions to 751 so I should be able to execute the script. But instead I get this error:

2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] allocator: system
2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] modules: none
2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] build environment:
2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] distarch: x86_64
2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] target_arch: x86_64
2016-08-28T16:15:15.311-0400 I CONTROL [initandlisten] options: { storage: { dbPath: "data/db" } }
2016-08-28T16:15:15.312-0400 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory data/db not found., terminating
2016-08-28T16:15:15.312-0400 I CONTROL [initandlisten] dbexit: rc: 100
Mongo is running!


When I run "mongod --dbpath data/db" in a shell window the command executes without a problem so what am I doing wrong?

Answer

I suggest to add full path to data/db.