Hi All
I am trying to create a simple script that will ssh to few devices and report the ssh version back in the following format
Hostname SSH version
###################################
<hostname1> <ssh version x>
<hostname2> <ssh version x>
The script is below but I am having problem matching the regex expression
#!/usr/bin/expect
# Here, we specify all our commands in a list, that we will issue one
# by one at a later time.
set commands [list "show ip ssh"]
set device_list [read [open "/<path>/test.txt"]]
set pass "******"
set prompt {([#>]) ?$}
# This command tells expect not to echo the output to the console.
exp_log_user 0
log_user 1
# Set each device's log file to be the name of the device...
set file_name ssh_output.txt
# We loop through each device in our list, one by one...
foreach device $device_list {
# we initiate the SSH connection
eval spawn ssh $device -l ******
match_max [expr 32 * 1024]
#If we see a message asking about the device's host key, accept it.
interact -o -nobuffer -re "assword: $" return
send "$pass\r"
foreach cmd $commands {
send "$cmd\r"
expect -re $prompt
exp_log_file -a $file_name
set values $expect_out(buffer)
set found [regexp { \bSSH\b } $values SSH hostname]
if {$found == 1} {
puts "Hostname SSH version\r"
puts "###################################\r"
puts "Hostname : $hostname\n";
puts "SSH version : $SSH\n";
} else {
puts "No match found!"
}
}
send "exit\r"
exp_close -i $spawn_id
exp_wait
}
Thanks
Pantelis