shell script - check mongod server is running

前端 未结 4 839
既然无缘
既然无缘 2021-02-02 03:57

I have a shell script to do some mongo db actions:

e.g. mongo testdb --eval \"db.dropDatabase()\"

BUT, if the mongod server is not running, I get:

4条回答
  •  清歌不尽
    2021-02-02 04:23

    this is what i run to check if mongod is up:

    # this script checks if the mongod is running.
    # if not, send mail
    #
    
    EMAILIST=dba@wherever
    
    
    
    `ps -A | grep -q '[m]ongod'`
    
    if [ "$?" -eq "0" ]; then
        exit 0
    else
        echo "The mongod server SB2MDB01 is DOWN" | mailx \
        -s "Server DOWN: SB2MDB01" $EMAILIST
    fi
    
    exit 0
    

提交回复
热议问题