Ibn Masood
Ibn Masood

Reputation: 1113

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?

Upvotes: 0

Views: 448

Answers (1)

Cyrus
Cyrus

Reputation: 88654

I suggest to add full path to data/db.

Upvotes: 1

Related Questions