cat 1chkping.sh
#!/usr/bin/sh
#
HOSTLIST="./hn"
LOCPLAT=`uname`
ONLST="./online.lst"
OFFLST="./offline.lst"
PINGLOG="./ping.log"
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NORMAL='\033[0m'
no_host_list(){
case ${LOCPLAT} in
Linux)
echo -e " ${RED}The host list file $1 is not exist or Empty!${NORMAL}"
;;
*)
echo " ${RED}The host list file $1 is not exist or Empty!${NORMAL}"
;;
esac
}
online_host(){
case ${LOCPLAT} in
Linux)
echo -e " ${GREEN} ${HN} is OnLine.${NORMAL}" >>${ONLST}
;;
*)
echo " ${GREEN} ${HN} is OnLine.${NORMAL}" >>${ONLST}
;;
esac
}
offline_host(){
case ${LOCPLAT} in
Linux)
echo -e " ${RED} $1 is OffLine!${NORMAL}" >>${OFFLST}
;;
*)
echo " ${RED} $1 is OffLine!${NORMAL}" >>${OFFLST}
;;
esac
}
offline_count(){
case ${LOCPLAT} in
Linux)
echo -e " ${RED} The `wc -l $1 | awk '{print $1}'` hosts are OffLine . ${NORMAL}"
;;
*)
echo " ${RED} The `wc -l $1 | awk '{print $1}'` hosts are OffLine .${NORMAL}"
;;
esac
}
online_count(){
case ${LOCPLAT} in
Linux)
echo -e " ${GREEN} The `wc -l $1 | awk '{print $1}'` hosts are OnLine . ${NORMAL}"
;;
*)
echo " ${GREEN} The `wc -l $1 | awk '{print $1}'` hosts are OnLine .${NORMAL}"
;;
esac
}
if [ -e ${HOSTLIST} -a -s ${HOSTLIST} ] ; then
>${ONLST}
>${OFFLST}
>${PINGLOG}
while read HN
do
case ${LOCPLAT} in
Linux)
ping ${HN} -c 1 -i 1 >>${PINGLOG}
;;
AIX)
ping -c 1 -w 1 -i 1 ${HN} >>${PINGLOG}
;;
HP-UX)
ping ${HN} -n 1 -m 1 >>${PINGLOG}
;;
esac
if [ $? != 0 ] ; then
offline_host ${HN}
else
online_host ${HN}
fi
done < ${HOSTLIST}
if [ -s ${ONLST} ] ; then
echo " `wc -l ${ONLST} | awk '{print $1}'` OnLine Host List :"
cat ${ONLST}
else
online_count ${ONLST}
fi
if [ -s ${OFFLST} ] ; then
echo " `wc -l ${OFFLST} | awk '{print $1}'` OffLine Host List :"
cat ${OFFLST}
else
offline_count ${OFFLST}
fi
else
no_host_list ${HOSTLIST}
fi
###END
阅读(2323) | 评论(0) | 转发(0) |