码迷,mamicode.com
首页 > 其他好文 > 详细

NEW MOE

时间:2018-12-26 16:56:27      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:res   efi   xxxxx   0.11   gateway   cte   ddr   var   eth   

[root@ChrisTest ~]# cd script/spawnL2SW/
[root@ChrisTest spawnL2SW]# ls
Done expired_files Sample worklog_2018-12-26_13:07:09
doshow.sh main_doshowall.sh SWlist.txt worklog_2018-12-26_13:07:19
[root@ChrisTest spawnL2SW]# cat doshow.sh
#!/usr/bin/expect -f

##Define Variables
#Define Timeout
set time 10
#Define Password
set passwd "XXXXXX"
set passwd2 "xxxxxxx"
set passwd2en "xxxx"
#Define Prompt
set prompt "CNAPS-UAT-SW01.>$"
set prompt2 "SH.
S.>$"
set prompt2en "SH.
S.#$"
#Define HOSTNAME, argv 0 means get the first parameters from input.
set HOSTNAME [lindex $argv 0]
#Define the last 4 characters of mac address
#set macaddr "ce8d"
set macaddr [lindex $argv 1]
#Login Gateway Switch
spawn ssh admin@10.116.12.250
expect {
"
yes/no" { send "yes\r"; exp_continue }
"Password:" { send "$passwd\r" }
}
expect -re "$prompt"
send "ssh $HOSTNAME\n"
expect {
"
yes/no" { send "yes\r"; exp_continue }
"*Password:" { send "$passwd2\r" }
}
expect -re "$prompt2"
send "enable\n"
expect "Password:"
send "$passwd2en\n"
expect -re "$prompt2en"
send "ter len 0\n"
expect -re "$prompt2en"
send "sh ip int b\n"
expect -re "$prompt2en"
send "sh mac addr | in $macaddr\n"
expect -re "$prompt2en"
send "exit\r"

[root@ChrisTest spawnL2SW]# cat main_doshowall.sh
#!/bin/sh

#Define Variable
LIST=./SWlist.txt
DATE=date ‘+%Y-%m-%d_%H:%M:%S‘

#Create Worklog Folder
mkdir ./worklog_$DATE

read -p ‘Pls input the last 4 characters of MACaddr for target client PC: ‘

#Recursive the IP addresses in SWList to run the Script doshow.sh
for TARGET in cat $LIST
do
echo $TARGET
./doshow.sh $TARGET "$REPLY" | tee ./worklog_$DATE/$TARGET.log
done

#Just for Test
#./doshow.sh 10.110.104.71 | tee ./worklog_$DATE/10.110.104.71.log

echo ‘ ‘
echo ‘ ‘
echo ‘ ‘
echo ‘ ‘
echo ‘ ‘

#################Export All Double-down Status Ports in 11F################
#Export Count of Port Status for Switches on 11 Floor.
SH11ESupupcount=`grep -rnh "GigabitEthernet.up.up" worklog$DATE/10.110.104.7 | wc -l<br/>SH11ESupdown_count=grep -rnh "GigabitEthernet.up.down" worklog_$DATE/10.110.104.7 | wc -l<br/>SH11ESdownup_count=grep -rnh "GigabitEthernet.down.up" worklog_$DATE/10.110.104.7 | wc -l<br/>SH11ESdowndown_count=grep -rnh "GigabitEthernet.down.down" worklog_$DATE/10.110.104.7 | wc -l`

SH11WSupupcount=`grep -rnh "GigabitEthernet.up.up" worklog$DATE/10.110.104.8 | wc -l<br/>SH11WSupdown_count=grep -rnh "GigabitEthernet.up.down" worklog_$DATE/10.110.104.8 | wc -l<br/>SH11WSdownup_count=grep -rnh "GigabitEthernet.down.up" worklog_$DATE/10.110.104.8 | wc -l<br/>SH11WSdowndown_count=grep -rnh "GigabitEthernet.down.down" worklog_$DATE/10.110.104.8 | wc -l`

echo "11F East Area UP\/UP count=$SH11ESupupcount" >> ./worklog$DATE/Count_Statistics
echo "11F East Area UP\/DOWN count=$SH11ESupdowncount" >> ./worklog$DATE/Count_Statistics
echo "11F East Area DOWN\/UP count=$SH11ESdownupcount" >> ./worklog$DATE/Count_Statistics
echo "11F East Area DOWN\/DOWN count=$SH11ESdowndowncount" >> ./worklog$DATE/Count_Statistics

echo "11F West Area UP\/UP count=$SH11WSupupcount" >> ./worklog$DATE/Count_Statistics
echo "11F West Area UP\/DOWN count=$SH11WSupdowncount" >> ./worklog$DATE/Count_Statistics
echo "11F West Area DOWN\/UP count=$SH11WSdownupcount" >> ./worklog$DATE/Count_Statistics
echo "11F West Area DOWN\/DOWN count=$SH11WSdowndowncount" >> ./worklog$DATE/Count_Statistics

#Export Port Status for all Switches.
grep -r "GigabitEthernet.down.down" worklog$DATE/10.110.104.* | awk -F"/" ‘{print $2,$3,$4}‘ >./worklog$DATE/11FDownDownPorts.txt

#################Export All Double-down Status Ports in 11F################

#################Find out the Port on Switch for specific Macaddr################
PortNum=grep -rh -B 1 ‘DYNAMIC Gi‘ worklog_$DATE/
#echo $PortNum
echo "The Port Number of $macaddr on switch is" >> ./worklog$DATE/PortNum.txt
echo "$PortNum" >> ./worklog
$DATE/PortNum.txt
PortNumResultSW=grep "#" worklog_$DATE/PortNum.txt | awk -F"#" ‘{print $1}‘
PortNumResultPT=grep DYNAMIC worklog_$DATE/PortNum.txt | awk ‘{print $4}‘ | uniq
echo ‘Switch:‘ "$PortNumResultSW" ‘Port:‘ "$PortNumResultPT" > worklog_$DATE/PortNumResult.txt
################Find out the Port on Switch for specific Macaddr################

################Export All Results################
echo ‘ ‘
echo ‘ ‘
echo ‘ ‘
echo ‘ ‘
echo ‘############################################‘
cat worklog_$DATE/CountStatistics
echo ‘ ‘
cat worklog
$DATE/PortNumResult.txt
echo ‘############################################‘
################Export All Results################

exit 1

[root@ChrisTest spawnL2SW]# cat SWlist.txt
10.110.104.71
10.110.104.72
10.110.104.73
10.110.104.74
10.110.104.75
10.110.104.76
10.110.104.81
10.110.104.82
10.110.104.83
10.110.104.84
10.110.104.85
10.110.104.86
10.110.104.91
10.110.104.92
10.110.104.93
10.110.104.94
10.110.104.95
10.110.104.101
10.110.104.102
10.110.104.103
10.110.104.104
10.110.104.105
10.110.104.106
10.110.104.111
10.110.104.112
10.110.104.113
10.110.104.114
10.110.104.115
10.110.104.117
10.110.104.119
10.110.104.121
10.110.104.122
10.110.104.123
10.110.104.124
10.110.104.151
10.110.104.156
10.110.104.157
10.110.104.158

NEW MOE

标签:res   efi   xxxxx   0.11   gateway   cte   ddr   var   eth   

原文地址:http://blog.51cto.com/3229026/2335455

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!