杂项,主要是系统调试相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

#!/bin/sh
CheckIPAddr()
{
echo ${1} | grep "^[0-9]\{1,3\}\.\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}$" > /dev/null;
if [ $? -ne 0 ] ;then
return 1
fi
ipaddr=${1}
a=$( echo ${ipaddr} | awk -F . '{print $1}' )
b=$( echo ${ipaddr} | awk -F . '{print $2}' )
c=$( echo ${ipaddr} | awk -F . '{print $3}' )
d=$( echo ${ipaddr} | awk -F . '{print $4}' )
for num in ${a} ${b} ${c} ${d} ; do
if [ ${num} -gt 255 ] || [ ${num} -lt 0 ]; then
return 1
fi
done
return 0
}
main()
{
if [ $# -lt 4 ];then
echo "Usage: ./pingctrl.sh <ip> <count> <interval> <timeout>"
return 1
fi
CheckIPAddr ${1}
if [ $? -ne 0 ];then
echo 'the IP address is illegal'
return 1
fi
while :
do
ping $1 -c $2 -W $4 > /dev/null;
if [ $? -ne 0 ];then
echo "host are not reachable"
reboot
break;
fi
sleep $3
done
}
main $@