-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcisco-grab-modules_SN.sh
executable file
·49 lines (44 loc) · 1.74 KB
/
cisco-grab-modules_SN.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#Variables
defdir=/home/kalina
scriptdir=$defdir
devip=$defdir/alldev3
ph=',' #place holder
result=$defdir/cisco_SN.txt
#Create a file with remote tcl commands
printf "sh inventory" > $defdir/cmdfile-inv
#Check file title
echo "Switch name"$ph"Module Name"$ph"Module Describe"$ph"Serial Number" > $result
#Check folder for temporary result save
[ -d "$defdir/temp-inv" ] || mkdir $defdir/temp-inv
#Creating a records of the unused ports for each device
cat $devip | while read line
do
#Getting credentials from line
host=`echo $line | cut -d',' -f5`
user=`echo $line | cut -d',' -f7`
pass=`echo $line | cut -d',' -f3`
epass=`echo $line | cut -d',' -f6`
#Temp dir
output=$defdir/temp-inv/$host
#Execute the script to $output in raw format
$scriptdir/vty_runcmd.exp -m ssh -h $host -u $user -p $pass -f $defdir/cmdfile-inv > $output
#
#Clear output: removing "^M", "tabulators", "--More--" and replacing more that 1 space to 1 space
sed -i 's/\x0D//g;s/\x08\{3\}//g;s/--More--//g;s/ \+/ /g' $output
devname=`cat $output | egrep ".*[>#]$" -m 1 | sed 's/[>#]//'`
#
cat $output | grep NAME: | while read name
do
#Get a module name and its description
module=`echo $name | cut -d, -f1 | sed s/NAME://g || unknown`
# deleted "sed 's/.$//'"
desc=`echo $name | cut -d, -f2 | sed s/DESCR://g || unknown`
#Grab the module SN
SN=`cat $output | grep -A 1 -e "$name" | grep -o "SN:.*" | sed s/SN://g || unknown`
#Save result
echo $devname$ph$module$ph$desc$ph$SN >> $result
done
echo "Host $host processed"
#rm $output
done