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:
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
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."
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