⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checksw.sh

📁 检测交换机的所有端口是否工作正常
💻 SH
字号:
#!/bin/bash#Author   : libo#Date     : 06/03/2007#Name     : CheckSW#Fonution : This shell is used to check the switch's port#*****************expression********************# The way to realize the function, we must create# the vlan  according to the vlan switch. we create vlan's ID# must equal to the switch's vlan ID.# The detials as follows:# For example:# First of all, if we want to test the Switch's port 1 and the vlan switch has created vlans which id is between 2~48.# we must create a vlan which id is 2 in localhost, and ping the destination ip, if ping'status OK, then the port1 is OK,# or it bad. when it finished, we must remove the vlan we created, then create a new vlan which vlanID increase 1, and repeat# the loop until the ports were tested over.#****************var declare*********************# SW_PORT_CONUT: the Switch's ports count# TestRestult_File : the var mark the restult will be write to the fileTestResult_File="TestResult.txt"echo "Please input the Switch Port's count :"read SW_PORT_COUNT#First, we write the log to the log file echo "TestResult_File is ${TestResult_File}"  echo "we test Switch's ports'count is :${SW_PORT_COUNT}" > ${TestResult_File} echo "if some ports are OK, we can consider the port 1 is OK"#****************************Create the vlan********************************#because of the vlanID must start with 2for((i=2;i<=${SW_PORT_COUNT};i++));do#start the loop#create the vlan vconfig add eth0 $i#set the Ip addr for every vlan deviceifconfig eth0.$i 192.168.$i.34ifconfig eth0.$i updone#*****************************Testing**************************************echo "Testing......................."#current test resutl#we ping the destination IP, and get the result from return stringfor((i=2;i<=${SW_PORT_COUNT};i++));do#ping -c 3 -w 1 192.168.$i.35temp_result=`ping -c 3 -w 1 192.168.$i.35|grep '% packet loss'|cut -d, -f3`#echo "the temp_result is : ${temp_result}"#we judge the result equal to the "0% packet loss"#if the condition is true ,the port is OK#or it is bad if [ "$temp_result" = " 0% packet loss" ] ;then    echo "we test port $i is OK" >> ${TestResult_File} else   echo "we test port $i is Bad" >> ${TestResult_File} fidone#***************************DestoryVlan************************* for((i=2;i<=${SW_PORT_COUNT};i++));do#start the loop#destory the vlanvconfig rem eth0.$idone     echo;echo;echo;echo;echo "********************** Test Result***********************"echo "If any port is OK, we can think the port(uplink) is OK"cat ${TestResult_File}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -