#!/bin/bash# executes # execution method: sh centospingbjbk.sh iplist1.txt# input: on the CentOS system Iplist.txt (IP list). Warning, can only be IP, cannot be host# output: faillist.txt (ping ip list), oklist.txt (ping ip list) # yuanlong.zhou# 2015.09.25iplist=$1cat /dev/null > faillist.txt && cat /dev/null > oklist.txtfor i in ' cat $iplist ' Do# centos is taking 6th, Mac is taking 7th ping= ' ping -c 1 $i | grep loss | awk ' {print $6} ' | awk -F "%" ' {print $1} ' if [ $ping == 100 ];thenecho ping $i fail >> faillist.txtelseecho ping $i ok >> Oklist.txtfidone test File iplist1.txt data: 10.0.1.110.10.1.1103.249.130.4210.211.55.1110.0.1.46127.0.0.1#!/bin/bash# Execute # execution method on Mac system: sh macpingbjbk.sh iplist2.txt# input: iplist.txt (IP list). Warning, can only be IP, cannot be host# output: &nbsP;faillist.txt (ping ip list), Oklist.txt (ping-through IP list) # yuanlong.zhou# 2015.09.25iplist=$1cat /dev/ Null > faillist.txt && cat /dev/null > oklist.txtfor i in ' cat $iplist ' Do# centos is taking 6th, Mac is taking 7th ping= ' ping -c 1 $i | grep loss | awk ' {print $7} ' | awk -F '% ' ' {print $1} ' if [ $ping == 100 ];thenecho ping $i fail >> faillist.txtelseecho ping $i ok >> Oklist.txtfidone test File IPLIST.TXT2 data: 10.0.1.110.10.1.110.211.55.1110.0.1.46 Improved (the script field distinguishes between CentOS and Mac) #!/bin/bash# on CentOS or Mac systems (scripts automatically distinguish whether the current system is CentOS or Mac) # Execute method: sh pingbjbk.sh iplist3.txt# input : iplist3.txt (IP list). Warning, can only be IP, cannot be host# output: faillist.txt (ping ip list), oklist.txt (ping ip list) # yuanlong.zhou# 2015.09.25iplist=$1os= ' uname ' CAT /DEV/NULL&NBsp;> faillist.txt && cat /dev/null > oklist.txtflag= ' $6 ' flag2= "100 "if [ $os == linux ];thenflag= ' $6 ' flag2=" "elseflag=" $7 "flag2=" 100.0 "fifor i in ' cat $iplist ' Do# centos is taking 6th, Mac is taking 7th # ping= ' ping -c 1 $i | grep loss | awk ' {print $6} ' | awk -F '% ' ' { print $1} ' ping= ' ping -c 1 $i | grep loss | awk ' {print $flag} " | awk -F "% " ' {print $1} ' if [ $ping == $flag 2 ];thenecho ping $i fail >> faillist.txtelseecho ping $i ok >> Oklist.txtfidone test File iplist3.txt data: 10.0.1.110.10.1.1103.249.130.4210.211.55.1110.0.1.46127.0.0.110.0.1.110.10.1.110.211.5 5.1110.0.1.46======================================================================================================================================================================================================== ==================================== The following is not tested by Telnet logon first, and then ping the host # telnetpingip.sh# touch telnetpingip.sh && chmod 755 telnetpingip.sh && vim telnetpingip.sh#!/usr/bin/expect -fset timeout 30set aip "10.0.1.1" set ausr "admin" set apwd "[email protected]" spawn telnet ${aip}expect "Username:" send "${ausr}\r" expect "Password:" send "${apwd}\r" # todo ping cmdexpect "]* "Interact (sleep 1;echo " root ";sleep 1;echo " 123456 ";sleep 1;echo " en "; sleep 1;echo "1qazse4";sleep 1;echo "conf t";sleep 1;echo "INT FA0/1"; sleep 1;echo "Switchport mode multi";sleep 1;echo "End";sleep 1;echo "Exit" ) | telnet 10.32.17.10
Ping to see if the device network is up to