#!/bin/sh
MM=`ps -ef|grep memcached|grep -v grep|wc -l`
while [ "$MM" -eq 0 ]
   do
   echo "$(date +%Y%m%d%H%M%S),the memcached is down,try to up it" >>/data/shell/men.log
   /usr/bin/memcached -d -u root -m 512 -p 39999 -c 1024
   sleep 2s
   MM=`ps -ef|grep memcached|grep -v grep|wc -l`
   done
   echo "$(date +%Y%m%d%H%M%S),the memcached is ok" >>/data/shell/men.log


使用ps 统计进程数,如果为零。则拉起程序

并记录log

date 用法参考http://www.cnblogs.com/peida/archive/2012/12/13/2815687.html