skynyrd
skynyrd

Reputation: 982

Identifying mongo server status from bash

I am writing a bash script in our linux server about extracting a report from MongoDB. In fact, there are two more replica servers and I should extract the report if the it is master at that time for that server. If not, script will not extract anything.

Is there a way to get that information from shell? Thanks.

Upvotes: 3

Views: 1530

Answers (1)

David Modica
David Modica

Reputation: 104

you have to run a command to find out if it the PRIMARY or not.

i have a "js" file which contains this:

`printjson(db.isMaster().ismaster);

then in my bash script i run execute this and act accordingly:

PRIMARY=`/usr/bin/mongo ${SERVERNAME}:${PORT} --quiet     ${SCRIPTDIR}/isMaster.js`;
#
#
if [ "$PRIMARY" != "false" ]; then
# it is the PRIMARY

cheers

Upvotes: 5

Related Questions