Sheepykins
Daemon Poster
- Messages
- 556
- Location
- Worcestershire, England
Hi Guys,
Having a little trouble with TCL/expect.
What started off as a simple script has rocketed away from me and unfortunately its causing me some grief.
My expect script is in the following format:
So far so good, expect matches against $engine and pushes my comment into my file with a time/date stamp.
My else statement doesnt work, but for what I want .... thats fine lol.
So now I want it to login and check 3 of my Cisco sensors and it does the above, checks all 3 and pumps 3 lines into the file about each one.
Them problem i'm having majorly is with the second sensor, if it becomes unavailable - my script stops and doesnt test the final sensor.
I have tried the timeout options I know but - due to my woeful inexperience with TCL i'm pretty annoyed.
Wishing I had time to learn it properly not mash something together but ....alas...
I'm hoping there are some veterans here who can show me the path!
Having a little trouble with TCL/expect.
What started off as a simple script has rocketed away from me and unfortunately its causing me some grief.
My expect script is in the following format:
#!/usr/bin/expect -f
log_user 0
###########
#Variables#
###########
set time [timestamp -format %H:%M:%S]
set date [timestamp -format %Y-%m-%d]
set ::logfile [open /tmp/output2 a]
set engine "AnalysisEngine.+Running"
set user "cisco"
set pass "password"
set sensor 10.1.1.1
######################
#Simple expect script#
######################
spawn ssh $user@$sensor
expect "*Password: "
send $pass\r
expect "*CiscoIPS# "
send "show version\r"
expect {
-re $engine {puts $::logfile "$time $date test success";}
else {puts $::logfile "$time $date test failed";}
}
send "exit\r"
log_file;
So far so good, expect matches against $engine and pushes my comment into my file with a time/date stamp.
My else statement doesnt work, but for what I want .... thats fine lol.
So now I want it to login and check 3 of my Cisco sensors and it does the above, checks all 3 and pumps 3 lines into the file about each one.
Them problem i'm having majorly is with the second sensor, if it becomes unavailable - my script stops and doesnt test the final sensor.
I have tried the timeout options I know but - due to my woeful inexperience with TCL i'm pretty annoyed.
Wishing I had time to learn it properly not mash something together but ....alas...
I'm hoping there are some veterans here who can show me the path!