Hello,
1st time visitor, and just learning some probably very basic scripting here, but any help would be appreciated.
GOAL: Login to a device on the network via CLI using a mix of bash/expect, and take into account different potential responses depending on the status of the device.
Example output from the device..
Copyright (c) 2013 ADVA Optical Networking SE. All rights reserved.
user@x.x.x.x's password:
********************************************************************************
Warning Notice: xxxx
********************************************************************************
Do you wish to continue [Y|N]-->
xxxxxxxx-->
So in the above example, the only portion that 'might' appear is the line "Do you wish to continue [Y|N]-->". I'm attempting to have expect recognize that and provide a response of 'y', and then continue on to the rest of the expect statements. Below are the 2 scripts I am using together which is a bash script calling the expect script.
BASH SCRIPT
source ~/scripts/config
for ip in $(cat ./IPs); do
./00_Configure_SNMP $ip $EUSER $EPASS >> 00_Results/ip_${ip}
done
EXPECT SCRIPT
#!/usr/bin/expect -f
set IPaddress [lindex $argv 0]
set Username [lindex $argv 1]
set Password [lindex $argv 2]
set timeout 3
spawn ssh $IPaddress
expect "password:"
send "$Password\r"
expect {
"\[Y|N\]-->" {
send "y\r"
}
}
expect ">"
send "configure snmp\r"
expect ">"
send "add community xxxxxx readwrite\r"
expect ">"
send "home\r"
expect ">"
send "configure system\r"
expect ">"
send "ftp enable\r"
expect ">"
send "home\r"
expect ">"
send "logout\r"
Whats happening currently is the script gets to the point after the password is entered, and bypasses the section for the entering of the y if wanting to continue. I'm not quite sure if my formatting is correct or ?
Thank you,
Lyle