#!/bin/sh while true; do #启动一个循环,定时检查进程是否存在 server=`ps aux | grep /opt/mongodb | grep -v grep` if [ ! "$server" ]; then echo `date "+%Y-%m-%d %H:%M:%S"` service restart #如果不存在就重新启动 nohup bin/mongod --dbpath /opt/mongodb/db > mongodb.nohup.out& #启动后沉睡10s sleep 10 fi #每次循环沉睡2s sleep 2 done