Kwatog Tech Notes
perpetual newbie, forever learner
Appending Timestamp in Expect Program
Published 2015-06-11
I needed to generate a unique filename within my expect program. Doing that in shell is easy but it's different with expect. So here's the sample.
Here's my actual code snippet. The first two lines are all that matter.
set systemTime [clock seconds]
set archtime [clock format $systemTime -format %y%m%d%H%M%S]
puts $archtime set newfile $filename append newfile "." $archtime
puts "$V_REN_SRC $filename $arcpath/$newfile "
send "$V_REN_SRC $filename $arcpath/$newfile\r "
expect { timeout { return 4 } -nocase "failed*sftp>" {
puts "ERROR: Unable to archive $filename to $archivepath/"
set rc "3"
}
-nocase "operation aborted.*sftp>" {
puts "ERROR: Unable to archive $filename to $archivepath/"
set rc "3"
}
-nocase "sftp>" { }
eof {
puts "puts ERROR: sftp process died unexpectedly at point 5!!"
send "quit\r" exit 9
}
I got this from the link below. https://www.tcl.tk/man/tcl8.5/tutorial/Tcl41.html