Created
October 27, 2015 17:21
-
-
Save jonaslsl/a55a92e596c4470e72bb to your computer and use it in GitHub Desktop.
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
### init.sh | |
#!/bin/bash | |
echo -n "Username: " | |
read username | |
export username | |
echo -n "Password: " | |
read -s password | |
export password | |
echo "\r" | |
echo -n "Enable password: " | |
read -s enable | |
export enable | |
echo "\r" | |
./check.sh $username $password $enable | |
### check.sh | |
#!/usr/bin/expect -f | |
#expect lib params | |
set timeout 20 | |
#init params | |
set user [lindex $argv 0] | |
set pass [lindex $argv 1] | |
set enablepass [lindex $argv 2] | |
#external files params | |
set f [open "command.list"] | |
set commands [split [read $f] "\n"] | |
close $f | |
set f [open "ip.list"] | |
set hosts [split [read $f] "\n"] | |
close $f | |
foreach ip $hosts { | |
#log params | |
set dir /home/scherer/ciscoasa/logs | |
set now [clock format [clock seconds] -format "%d.%m.%y_%Hh%Mm%Ss"] | |
#puts "$now" | |
log_file -a $dir/$ip$now.log | |
send_log "### /START-SSH-SESSION/ IP: $ip @ [exec date] ###\r" | |
#connection | |
spawn ssh -o "StrictHostKeyChecking no" $user@$ip | |
#init connetion | |
expect "*assword:" | |
send $pass | |
send "\r" | |
expect "*>" | |
send "enable\r" | |
expect "*assword:" | |
send $enablepass | |
send "\r" | |
#executing commands list | |
foreach cmd $commands { | |
expect "*#" | |
send "$cmd\r" | |
} | |
#exiting | |
expect "*#" | |
send "exit\r" | |
expect eof | |
log_file | |
} | |
close | |
### command.list sample | |
terminal page 0 | |
show ver | |
show int ip bri | |
show run int | |
show interfaces all | |
show conn count | |
show run arp | |
show arp stat | |
sh arp | |
show vlan | |
show crypto ipsec stats | |
show run route | |
show route | |
show rip database | |
show failover | |
show failover state | |
show mem | |
show cpu usage | |
show environment | |
show xlate | |
show run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mass ssh command execution
Execute a list of commands in many remote Cisco devices.
Great for environment checklists and automation.
How to