Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Expect log_file Issue

2,307 views
Skip to first unread message

monkeytime

unread,
Oct 31, 2007, 11:28:07 AM10/31/07
to
Hi,

I've designed an Expect script to login to a device and turn on it's
syslog functionality. The syslog only sends to STDOUT, so a log_file
captures all of the output.

Once the syslog data starts streaming to STDOUT, I just want the
log_file to keep capturing data until I terminate the Expect script
manually. The issue that comes up is that after issuing the syslog
"on" command, the Expect script terminates and the log_file only
contains the output up to the last Expect command that was issued.

Is there a way I can leave the Expect script "open-ended" or still
running so that STDOUT data still goes to the logfile? I've tried a
"while" loop, timeout settings, sleep settings and leaveopen settings
and nothing worked. I've added a command at the end of the script to
expect bogus data (eg. jsdf98weeufh983r) that I know would never
appear, but that only logs about 10 lines of syslog data and then
terminates.

Any ideas would be greatly appreciated.

Glenn Jackman

unread,
Oct 31, 2007, 1:03:41 PM10/31/07
to

You'll have to show us what you've got so far.

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

monkeytime

unread,
Oct 31, 2007, 2:04:31 PM10/31/07
to

Thanks for the quick reply, Glenn. Here's the code:

#!/usr/local/bin/expect --

# Set the date.
set date [timestamp -format %C%y%m%d]

# Set the command line arguments.
set ip [lindex $argv 0]

# Create the log file directory.
system `/bin/mkdir /home/vconf/logs/$date`

# Set the log file.
spawn $env(SHELL)
log_file -noappend /home/vconf/logs/$date/$ip-$date.log

# Set host variables.
set pcommand "xxxxxxxx"

# Telnet to the host.
spawn /usr/bin/telnet $ip

# Login to the device.
expect "Password:"
send "$pcommand\r"

# Send the "syslog on" command.
expect "OK"
send "syslog on\r"

On a real telnet session, the "syslog on" command will begin to send
data to STDOUT and one can watch the data fly by. The Expect script,
however, will terminate and return back to the prompt after the
"syslog on" command. What could I append to the script to keep STDOUT
data flowing to the log_file?

Thanks,

Paul

Frank Ranner

unread,
Nov 1, 2007, 2:19:33 AM11/1/07
to

expect "hell to freeze over"

Mark Janssen

unread,
Nov 1, 2007, 3:55:26 AM11/1/07
to

You could append the following (from http://wiki.tcl.tk/3178):

expect {
"\n" {
puts "$expect_out(buffer)"
exp_continue
}
eof {
puts "$expect_out(buffer)"
}
} ; # RJ


Making sure this outputs to the log file is left as an exercise for
the reader.

Mark

Bruce Hartweg

unread,
Nov 1, 2007, 9:08:13 AM11/1/07
to
probably want to expect a timeout as well, (or set the timeout to 1-)
so if there is a lull in activity you won't bail.

Bruce

monkeytime

unread,
Nov 1, 2007, 1:59:47 PM11/1/07
to
> You could append the following (fromhttp://wiki.tcl.tk/3178):

>
> expect {
> "\n" {
> puts "$expect_out(buffer)"
> exp_continue
> }
> eof {
> puts "$expect_out(buffer)"
> }
> } ; # RJ
>
> Making sure this outputs to the log file is left as an exercise for
> the reader.
>
> Mark

Mark,

Excellent tip - worked perfectly! Thanks very much for your help.

Paul

0 new messages