Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 158

Expect Script TCL ending early

$
0
0

I have the following expect script which works for the most part. I have it connecting to a Cisco switch (eventually a couple hundred) and configuring syslog servers. It checks to make sure that buffering wasn't already configured and if it isn't, set it.

If "logging buffered" is set, the script works fine. However, if "no logging buffered" is present, the script dies early before saving the config.

    set timeout -1    set ip [lindex $argv 0]    set host [lindex $argv 1]    set username "admin"    set password "password"    set prompt "#|%|>|\$ $"    set timestamp [timestamp -format %Y-%m-%d_%H:%M]    log_file ./$host.$timestamp.log    spawn ssh -o StrictHostKeyChecking=no $username@$ip    match_max 100000    expect {"assword:" { send "$password\r" }"continue connecting (yes/no)?" {        send "yes\r"            expect {"assword:" { send "$password\r" }            }        }    }    expect "#"    send -- "\r"    expect "#"    send -- "conf t\r"    expect "#"    send -- "logging on\r"    expect "#"    send -- "do show run | inc logging buffered\r"    expect {"no logging buffered" {send "logging buffered 16384\r"; exp_continue}"#"  {send "\r"}           }    expect "#"    send -- "logging host 1.2.3.4 transport tcp port 514\r"    expect "#"    send -- "logging host 1.2.3.5 transport tcp port 514\r"    expect "#"    send -- "logging trap notifications\r"    expect "#"    send -- "end\r"    expect "#"    send -- "wr mem\r"    expect "#"    send -- "exit\r"

With "no logging buffered" present

spawn ssh -o StrictHostKeyChecking=no admin@192.168.1.2(admin@192.168.1.2) Password:core-switch#core-switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.core-switch(config)#logging oncore-switch(config)#do show run | inc logging bufferedno logging bufferedcore-switch(config)#logging buffered 16384core-switch(config)#core-switch(config)#logging host 1.2.3.4 transport tcp port 514core-switch(config)#logging host 1.2.3.5 transport tcp port 514core-switch(config)#logging trap notificationscore-switch(config)#endroot@ubuntu:~/test#

With "logging buffered xyz" present

root@ubuntu:~/test# ./config-syslog-password.shspawn ssh -o StrictHostKeyChecking=no admin@192.168.1.2(admin@192.168.1.2) Password:core-switch#core-switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.core-switch(config)#logging oncore-switch(config)#do show run | inc logging bufferedlogging buffered 16384core-switch(config)#core-switch(config)#logging host 1.2.3.4 transport tcp port 514core-switch(config)#logging host 1.2.3.5 transport tcp port 514core-switch(config)#logging trap notificationscore-switch(config)#endcore-switch#wr memBuilding configuration...[OK]core-switch#root@ubuntu:~/test#

Now I know its something to do with the TCL but I can't figure out what. Any help will be appreciated.


Viewing all articles
Browse latest Browse all 158

Latest Images

Trending Articles



Latest Images