#!/bin/sh pingcmd(){ PRE="server $1 Ping $2" MAILADD="123@qq.com" ping -w 1 -c 1 $2>/dev/null ret=$? if [ $ret -eq 0 ] then echo "$PRE OKn" | mail -s "$PRE status" $MAILADD else echo "$PRE ERRORn" | mail -s "$PRE status" $MAILADD fi return 0 } mainserver="192.168.1.3" slaveserver="192.168.1.2" pingcmd $mainserver $slaveserver