简体   繁体   中英

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?

我建议将完整路径添加到data/db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM