When you use 'clock format' using %k (without the leading zero for the hour field) it pads single digit hours with a space. This extra space generates an empty list element when passed to split and causes the TCL error about a null length string.
Rule snippet showing the problem:
log local0. "Clock output: [clock format [clock seconds] -format {%A %k %M}], \$k: $k"
set k [split [clock format [clock seconds] -format {%A %k %M}] " "]
log local0. "\$k split output llength: [llength $k]"
Log output:
Clock output: Thursday 9 05, $k: Thursday {} 9 05
$k split output llength: 4
Rule snippet:
log local0. "Clock output: [clock format [clock seconds] -format {%A %H %M}], \$H: $H"
set H [split [clock format [clock seconds] -format {%A %H %M}] " "]
log local0. "\$H split output llength: [llength $H]"
Log output:
Clock output: Thursday 09 05, $H: Thursday 09 05
$H split output llength: 3
You can work around this by using scan to parse the day, hour and minute regardless of the spaces:
Get time in seconds, formatted as day of week (%A) hour (%k) minute (%M)
Use scan to save output as $cur_day $cur_hour $cur_minute
scan [clock format [clock seconds] -format {%A %k %M}] {%s %d %d} cur_day cur_hour cur_minute
set cur_time ${cur_hour}${cur_minute}
So this example should work. In a simple test if the cur_time is 600 the comparison 600 >= 0600 is true. Though I haven't tested the rule completely.
when HTTP_REQUEST {
Change the following to set schedule
set maintenance_start_time "0200";
set maintenance_end_time "0600";
set maintenance_day "Saturday";
Get time in seconds, formatted as day of week (%A) hour (%k) minute (%M)
Use scan to save output as $cur_day $cur_hour $cur_minute
scan [clock format [clock seconds] -format {%A %k %M}] {%s %d %d} cur_day cur_hour cur_minute
set cur_time ${cur_hour}${cur_minute}
log local0. "\$cur_day: $cur_day, \$cur_hour: $cur_hour, \$cur_minute: $cur_minute, \$cur_time: $cur_time"
if { ($cur_day eq $maintenance_day) &&
($cur_time >= $maintenance_start_time) &&
($cur_time <= $maintenance_end_time) } {
HTTP::respond "Maintenance message"
log local0. "Maintenance message"
}
}
Aaron