Scripts, usually I write some because I don’t like repetitive tasks and I’m lazy, meaning I prefer automation over useless hard work.
Don’t know where I found this quote but I like it:
Don't spend your time doing work a well-trained monkey could do.
Today’s request was quite simple: get model and serial number from a bunch of Cisco switches.
The script reads from a file that contains a list of IP addresses, all the devices must have a snmp community with read priviledge.
The script is quite readable: for each line of the input file it does some snmp read operations and print the result when finished.
Sed commands are used to clean the output of the snmp output.
Replace variable community with the correct value for your environment.
#!/bin/bash community=MYCOMMUNITY while IFS='' read -r line || [[ -n "$line" ]]; do hostname=$(snmpwalk -v 2c -c $community -O v -L n $line 18.104.22.168.22.214.171.124.1.3 | sed 's/^.*://g' | sed 's/"//g') model=$(snmpwalk -v 2c -c $community -O v -L n $line 126.96.36.199.188.8.131.52.184.108.40.206.1001 | sed 's/^.*://g' | sed 's/"//g') serial=$(snmpwalk -v 2c -c $community -O v -L n $line 220.127.116.11.18.104.22.168.1.2.19 | sed 's/^.*://g' | sed 's/"//g') echo -e $line'\t'$hostname'\t'$model"\t"$serial done < "$1"
where file switchlist.txt is a simple list of IP addresses.
The final result is a list of values separated by a tab os it is easy to copy and paste in a spreadsheet.
hostname model serial
I added this script to my GitHub repository.
Enjoy!comments powered by Disqus