Skip to content

Instantly share code, notes, and snippets.

@gottaloveit
Created January 14, 2016 12:58
Show Gist options
  • Save gottaloveit/c69bc690b4aec6a56294 to your computer and use it in GitHub Desktop.
Save gottaloveit/c69bc690b4aec6a56294 to your computer and use it in GitHub Desktop.
Storing for in case of future need. This runs to pull configs from network dell 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 …
#!/bin/bash
# written for dell network N2048 switch
# example usage ./dell_switch_telnet.sh "DEVICE_NAME" DEVICE_IP TFTPD_SERVER_IP "COLO_FACILITY_NICKNAME"
# Storing for in case of future need. This runs to pull configs from network dell 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/$1
(expect -c "
set timeout 20
spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ip
expect \"password: \"
send \"PASSWORD-REDACTED-FOR-SECURITY\r\"
expect \"*sw2>\"
send \"en\r\"
expect \"*sw2\#\"
send \"copy startup-config tftp://$myip/$host.cfg\r\"
expect \"n)\"
send \"y\"
expect \"*\#\"
send \"exit\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