shell判断通断,ping通则ssh,判断输入IP格式
read -p "pleas input ip " ip
regex="\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\b"
ckStep2=`echo $ip | egrep $regex | wc -l`
if [ $ckStep2 -eq 0 ]
then
echo "The string $ip is not a correct ipaddr!!!"
else
ping -c2 -i0.1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo "$ip is up"
ssh $ip
else
echo "$ip is down"
fi
fi