Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop and date in expect-script

Status
Not open for further replies.

geirendre

Vendor
Aug 13, 2001
603
NO
Hi, I'm trying to make an expect-script that telnets
into a host, and extracts data from it into a file.
I have the script up and running, sort of...
It outputs the info into the file, but without any "timestamp".
I'd like to use the date command to put the time into
the same file with the rest of the data, but only gets
error messages when I try to use it.
I'm new to expect, so bare with me.
Are not *nix-commands accessible from within expect?
Here is my code:
Code:
#!/usr/bin/expect -f

set force_conservative 0  ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
set thebox [lindex $argv 0] ;# henter lokasjon som skal resetter fra hovedscript
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout -1
spawn telnet $thebox
match_max 100000
expect "Uname:"
send -- "myusername\r"
expect "PWD:"
send -- "mypassword\r"
expect "RDY>"

log_file logginfo.txt
for {} 1 {} {
send -- "statcs\r"
expect ":"
send -- "O\r"
expect ":"
send -- "BWUSAGE\r"
expect "RDY>"
sleep 60
}
send -- "logoff\r"
expect "sure?"
send -- "y\r"
expect "off."
How can I ad the date command inside the for-loop?

What I want is the script to do is:
1 - Loggin automaticaly. - works
2 - Extract some data. - works
3 - Insert time and date - help needed
4 - Repeat the extract - works
5 - Stop after x number of repeats, or a spesified time - help needed.
6 - Be stopped with Ctrl-c - works sometimes.
7 - Logout when finished - works, sort of
(script never gets to this point as is now, it loops forever)
think I need a better loop, say a while-loop maby??

Glad for any advice on this rather long list :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top