30 January, 2014

Shell script for automated config pull from Cisco Nexus switches.


root@ubu:~/skrp# cat copyrun2.sh
 
#!/bin/bash
user=myusername
pass=mypassword 
serverid="server.txt" 
while read line;do
  now=$(date +"%d.%m.%Y_%H:%M:%S")
  sshpass -p $pass ssh -t -o StrictHostKeyChecking=no -l $user $line << EOF > $line'_'$now.txt
  sh hostname
  sh policy-map interface control-plane
EOF
done <$serverid

root@ubu:~/skrp# cat server.txt 
192.168.111.23
192.168.111.13

root@ubu:~/skrp# sh copyrun2.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Nexus 3000 Switch
Pseudo-terminal will not be allocated because stdin is not a terminal.
Nexus 3000 Switch
root@ubu:~/skrp#
root@ubu:~/skrp# ls -la
-rw-r--r-- 1 root root 4579 Jan 30 11:00 192.168.111.23_30.01.2014_11:00:33.txt
-rw-r--r-- 1 root root 4587 Jan 30 11:00 192.168.111.13_30.01.2014_11:00:35.txt


No comments:

Post a Comment