I've been working on this script for hours trying to figure out why it's not working. The following code is a portion of the whole script. This code is actually within a "for" loop. here's the code:
Code:
set timeout 3
spawn -noecho ssh ${account}@$ipAddress
send_user "Configuring $equipment...\n"
log_user 0
# LOOKING FOR THE PASSWORD PROMPT
expect {
"yes/no" {
send "yes\r"
exp_continue
}
"*?assword:*$" {
send "$pass\r"
}
timeout {
set error "$equipment $ipAddress is unreachable\n"
set passLog "$passLog$error"
continue
}
}
# LOOKING FOR THE PROMPT
expect {
"#" {
send "ls\r"
log_user 1
send_user "Working...\n"
send "exit\r"
send_user "Working2...\n"
}
"Permission denied" {
set error "Wrong Password for $equipment $ipAddress using user \"$account\".\n"
set passLog "$passLog$error"
continue
}
}
The script was made to ensure a clean login is made and report any unreachable ip addresses or bad password inputs.
My greatest concern lies within the expected "#" portion. The lines with "Working..." and "Working2..." both display. So it seems to be bypassing my "send ls/r" and the "send exit/r". I don't know why it's doing that. Any help would be great.