mongodb - shell script - check mongod server is running -
i have shell script mongo db actions:
e.g. mongo testdb --eval "db.dropdatabase()"
but, if mongod server not running, get:
mongodb shell version: 2.0.4 connecting to: testdb tue may 14 04:33:58 error: couldn't connect server 127.0.0.1 shell/mongo.js:84
is there way in mongo can check connection status? want like:
if(mongod running): mongo testdb --eval "db.dropdatabase()" else: echo "pls make sure mongod running" exit 1
you should able create bash script this:
mongo --eval "db.stats()" # simple harmless command of sort result=$? # returns 0 if mongo eval succeeds if [ $result -ne 0 ]; echo "mongodb not running" exit 1 else echo "mongodb running!" fi
Comments
Post a Comment