Created
January 14, 2016 13:01
-
-
Save gottaloveit/bd2cb5e2f81cf7c22984 to your computer and use it in GitHub Desktop.
Storing for in case of future need. This runs to pull configs from network cisco switches and compares and saves config file to a local network file share location using CIFS and a network file server to store the confgs. It work for the situation it is in, they may not work for every situation, I do not take liability for anything that might go…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# written for a Cisco WS-C2960S-48TD-L | |
# example usage ./cisco_switch.sh "DEVICE_NAME" DEVICE_IP TFTPD_SERVER_IP "COLO_FACILITY_SHORTNAME" | |
# Storing for in case of future need. This runs to pull configs from network cisco switches and compares and saves config file | |
# to a local network file share location using CIFS and a network file server to store the confgs. It work for the situation | |
# it is in, they may not work for every situation, I do not take liability for anything that might go wrong, nor do I support | |
# these scripts outside of my own usage. | |
host=$1 | |
ip=$2 | |
myip=$3 | |
colo=$4 | |
now=`date +"%Y_%m_%d"` | |
tftp=/tftpboot | |
compare_dir=$tftp/$host | |
backup_path=/network_device_backups/networking_devices/$colo/switches/$host | |
(expect -c " | |
set timeout 5 | |
spawn telnet $ip | |
expect \"*rd: \" | |
send \"REDACTED-FOR-SECURITY\r\" | |
expect \"*> \" | |
send \"enable\r\" | |
expect \"Password: \" | |
send \"REDACTED-FOR-SECURITY\r\" | |
expect \"*\# \" | |
send \"show startup-config | redirect tftp://$myip/$host.cfg\r\" | |
expect \"*\# \" | |
send \"exit\r\" | |
exit | |
") | |
mkdir -p $compare_dir | |
mkdir -p $backup_path | |
touch $compare_dir/$host.cfg | |
md5=`md5sum $compare_dir/$host.cfg | awk '{ print $1 }'` | |
echo | |
echo | |
echo "current md5: $md5" | |
newmd5=`md5sum $tftp/$host.cfg | awk '{ print $1 }'` | |
echo | |
echo "new md5: $newmd5" | |
echo | |
if [ $md5 != $newmd5 ] | |
then | |
cp $tftp/$host.cfg $compare_dir/$host.cfg | |
cp $tftp/$host.cfg $backup_path/$host_$now.cfg | |
echo "copied files" | |
fi | |
rm $tftp/$host.cfg | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment