2019-01-25

Some tcl stuff

At work, there was an expect script that, on a daily basis, ran a job that created some files for handheld computers used by our merchandisers. The script used a static date to create those files. As a result, any changes such as new customers made after that static date would not be included in the files.

In 2014, I modified the script to calculate the date instead. The nature of the job required using Sunday's date to ensure as much information as possible was included for the handheld computers.

I stumbled across a file containing some of the middle steps I took to modify the script calculate the correct date to use.


x=091509
y=$(printf 'puts [clock format [clock add [clock scan "%s" -format "%%m%%d%%y"] -1 day] -format "%%Y%%m%%d"]' "091509" | tclsh)
puts [clock format [clock add [clock seconds] -1 day] -format %Y%m%d]

set current_date [clock seconds]
set day_of_week [clock format $current_date -format %w]
set tmp "${day_of_week} days"
set relative_time  [clock scan "-${day_of_week} days" ]
set sunday [clock format [expr $current_date - $relative_time] -format %m%d%y]

puts [clock format [clock scan "-[clock format [clock seconds] -format %w] days" ] -format %m%d%y]

and the final code that went into the file.

set sunday [clock format [clock scan "-[clock format [clock seconds] -format %w] days" ] -format %m%d%y]
send -- "${sunday}\r"

Time being what it is, I really don't remember how this works. I did a lot of googling about tcl at the time. This script was effectively retired two years ago.

No comments:

Post a Comment

Let's get a proper domain for this!

I created this blog to document some of the stuff I do (mostly as a reminder to myself but if it helps someone elsešŸ¤·). For some work I may ...