检测ip是否ping通和ssh端口是否通

#! /bin/bash
port=22
for i in `cat $1`
do 
  ping -c 2 $i  >/dev/null 2>&1
  if [ $? -eq 0 ];then
    echo -e "33[32m${i} is up33[0m"
    echo $i >> ip_up.txt
    ssh $i uptime
    if [ $? -eq 0 ];then
      echo -e "33[32m ip: ${i} port: ${port} is UP!33[0m"
      echo "$i $port"  >> ip_port_up.txt 
    else
      echo -e "33[31m ip: ${i} port: ${port} is DOWN!33[0m"
    fi     
  else
    echo -e "33[31m${i} is down33[0m"
    echo "$i $port"  >> ip_port_down.txt  
    echo $i >> ip_down.txt
  fi 
done 
原文地址:https://www.cnblogs.com/shanghai1918/p/13226690.html