cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1356
Views
0
Helpful
0
Replies

How can confirm switch configure with expect script

Rojin
Level 1
Level 1
 

i am new in expect script ,i need your help for my script.in my script i ask for configure switch (for creat automaticaly vlan and tunking vlan ) its good works. in secondly i said in output show running,its  works too,

#!/usr/bin/expect -f
#set variables
set hostname ...
set username..
set ip ...
foreach hostname [array names interface] {
set timeout 10
match_max 500000
# Log results
log_file -a ~/results.log

send_user "\n"
send_user ">>>> Working on $hostname @ [exec date]<<<< \n"
send_user "\n"
#ssh
spawn ssh -2 -o strictHostKeyChecking=no $username\@$ipaddress
expect "username:"
send "$username\r"
expect "#"
expect "password:"
send "$password\r"
expect -re $prompt
#enable configure mode
send "conf t\n"
expect "(config#)"
#vlan trunking mode
send "$interface($hostname)\n"
expect "(config-if-range)#"
send "switchport access vlan 9\n"
expect "(config-if-range)#"
send "switchport trunk encapsulation dot1q\n"
expect "(config-if-range)#"
send "switchport mode trunk\n"
expect "(config-if-range)#"
send "switchport trunk allowed vlan 7\n"
expect "(config-if-range)#"
send "end\n"
expect "#"
send "write mem\n"
expect "#"

send "terminal length 0\r"
expect "#"
send "show running-config\r"
expect "#"
}
set output $expect_out(buffer)
#Here dont working 
exp_sleep 1
stty echo
send_user -- "Are you sure configuration is finished?(Y/n):\n"
expect_before  "(yes/no)?"
send_user -- "\n
if  [ "$(#)"  !=  "yes" ];then
[  send_user "exit\n" ]
expect "#"
else
return
exp_send -- "\n"

puts "$output"
expect eof
exit

but in finally i want ask user "Are u sure configuration is finished ? " its for checking configure switch ,if yes exit and if not can return ,but i cant write end of part script

please help me for finally step, Danke

0 Replies 0
Review Cisco Networking for a $25 gift card