$expect_script = <<<EOD
#!/usr/bin/expect -f
exp_internal 1
log_user 1 ;# Enable logging of user interaction
set timeout 20
# Start Telnet session
spawn telnet $telnet_host
# Handle initial banners or messages
expect {
"User Access Verification" { exp_continue }
"Username:" { send "$telnet_usernamer" }
}
# Expect password prompt and send password
expect "Password:"
send "$telnet_passwordr"
# Expect the command prompt after successful login
expect "#"
# Send each command from the array except 'reboot'
foreach command [split "$command_interface" "n"] {
if { [string match "*reboot*" "$command"] } {
# If the command is 'reboot', handle it separately
send "$commandr"
expect {
"Confirm to reboot.*" {
send "yesr"
expect "#"
}
timeout { puts "Timed out waiting for reboot confirmation prompt."; exit 2 }
}
} else {
# For all other commands
send "$commandr"
expect {
"#" {
set output $expect_out(buffer)
}
timeout {
puts "Timed out waiting for command prompt."
exit 1
}
}
}
}
# Send exit command to close the Telnet session
send "exitr"
# Wait for session to end
expect eof
# Output the entire buffer captured
puts "$output"
EOD;
$commands = [
"config t",
"pon-onu",
"pon-onu-mng gpon-onu_1/14/8:45",
"reboot"
];
this shoud be running like this ,sampling from terminal
OL01-NGN-SMG-ERLGOD#config t
%Info 20272: Enter configuration commands, one per line. End with CTRL/Z.
OL01-NGN-SMG-ERLGOD(config)#pon-onu-mng gpon-onu_1/14/8:45
OL01-NGN-SMG-ERLGOD(gpon-onu-mng 1/14/8:45)#reboot
Confirm to reboot? [yes/no]:yes
but somehow the confrimation yes can not be put and resulted
Username:
ossapp01
Password:
OL01-NGN-SMG-ERLGOD#config t
%Info 20272: Enter configuration commands, one per line. End with CTRL/Z.
OL01-NGN-SMG-ERLGOD(config)#pon-onu
%Error 20203: Incomplete command.
OL01-NGN-SMG-ERLGOD(config)#pon-onu-mng gpon-onu_1/14/8:45
OL01-NGN-SMG-ERLGOD(gpon-onu-mng 1/14/8:45)#reboot
Confirm to reboot? [yes/no]:Timed out waiting for reboot confirmation prompt.
help me modify the expect script to achieve this, thankyou in advance