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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Date named file with Expect

Status
Not open for further replies.

RF101

Technical User
May 17, 2006
33
US

Hello,

I am new to TCL and Expect. I wrote an Expect script that pulls the data that I want but I would like to pull it every day and automatically assign the days date as part of the file name.

I tried playing around with exec data but I could not get teh syntax down.

my current code:

# expect -f ofcvar.txt > ofcvar_20080818.txt

Could someone help me figure out the syntax to replace the date automatically every day?

TIA,

RF
 
Thanks for the quick response.

If ofcvar.txt is my command reference for the expect script and I add this line of code within the file how would I call it to create the file name with the date?

My current ofcvar.txt file contents, simple I know:

set username xxx
set pass xxx
set host xxx.com

spawn telnet ${host}

expect -re "login:"
send "${username}\r"

expect "password:"
send "${pass}\r"

expect -exact "Press <enter> to continue..."
send -- "\r"



RF
 
Full disclosure: I don't speak Expect.

From your first post, I don't see how the contents matter. You had
# expect -f ofcvar.txt > ofcvar_20080818.txt
and you wanted (I thought) to change 20080818 to be any current date. Assuming that Expect processes all of Tcl as well as its own exotica:
set tdate [clock format [clock seconds] -format %Y%m%d]
set newName ofcvar_
append newName $tdate
append newName ".txt"
# expect -f ofcvar.txt > $newName


_________________
Bob Rashkin
 
This is awesome. Thanks for your help.

One more question.

When I type in the commands above at the expect prompt it works exactly like I wanted it but when I type the commands into a new tcl file and execute it it fails to send the last command successfully.

set tdate [clock format [clock seconds] -format %Y%m%d]
set newName ofcvar_
append newName $tdate
append newName ".txt"
send "expect -f ofcvar.txt > $newName\r"


I get this at the prompt:

xpect -f ofcvar.txt > ofcvar_20080819.txt

I am sure there is a simple fix. I tried with and without the # in front like your example but that did not seem to work.
 
Again, I don't speak Expect. That said, from your example, it appears that "send" and "expect" are exclusive, vis:
expect "password:"
send "${pass}\r"

So it would seem that either you want:
expect -f ofcvar.txt > $newName
or
send "-f ofcvar.txt > $newName\r"

but I don't know what either of them mean.

_________________
Bob Rashkin
 
Resolved. I decided to place everything in one script instead of trying to call a second one within the first.

Thanks,

RF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top