Forum Discussion
Tim_Moomaw_9220
Nimbostratus
Nov 09, 2008Scheduled Maintenance Window
--- Obligatory "I'm new to iRules" ----
I'm trying to create a rule to return a maintenance page every Saturday morning between 0200 and 0600. I have copied a few examples from DevCentral which work great except for any period of time that includes an 08 or 09. The log entries clearly indicate that it's having an issue with non-octal numbers being returned but I can't figure out how to get around it. I'm betting it's something hugely simple. Suggestions welcomed. Here's the rule as it's written now and the error that is received at 0208, 0209, 0308, 0309,08xx, 09xx etc. Thanks in advance.
when HTTP_REQUEST {
Change the following to set schedule
set start_time "0200";
set end_time "0600";
set day "Saturday";
set l [split [clock format [clock seconds] -format {%A %H %M}] " "]
set cur_day [lindex $l 0]
set cur_time [expr [expr {[lindex $l 1] *100}] + [lindex $l 2]]
if { ($cur_day eq $day) &&
($cur_time >= $start_time) &&
($cur_time <= $end_time) } {
HTTP::respond ----text here----
TCL error: m-window-test HTTP_REQUEST - cant use invalid octal number as operand of * while executing expr {[lindex $l 1] *100}
Also receive this error:
TCL error: m-window-test HTTP_REQUEST - expected integer but got 08 looks like invalid octal number while executing expr [expr {[lindex $l 1] *100}] + [lindex $l 2]]
- Tim_Moomaw_9220
Nimbostratus
Also receive this message. - hwidjaja_37598
Altostratus
Try this workaround out:regexp {(\d+)\s+0*(\d+)\s+0*(\d+)} \ [clock format [clock seconds] -format {%u %H %M}]\ match cur_day Hour Min set cur_time [expr ($Hour * 100) + $Min]
set l [split [clock format [clock seconds] -format {%A %H %M}] " "] set cur_day [lindex $l 0] set cur_time [expr [expr {[lindex $l 1] *100}] + [lindex $l 2]]
- hoolio
Cirrostratus
You can change the format strings in clock to eliminate the leading zero. This prevents expr from interpreting the numbers as octal values. - hoolio
Cirrostratus
And actually, based on your description, I don't think you need to use minutes. If you just check if the hour is greater than 2 and less than 6 you could ignore the minutes. - Tim_Moomaw_9220
Nimbostratus
Great idea Aaron! Not quite there yet though. Sorry to be a pest..... - Tim_Moomaw_9220
Nimbostratus
Aaron, - Tim_Moomaw_9220
Nimbostratus
To Update - I have had no time to investigate this further, but I have put the following in place that works great for the purpose at hand, which is to return an outage page between 0200 and 0600 on Saturdays.- snip - will be available again at 6:00am.
- As an aside here, I just updated the "iRule Maintenance Windows" tech tip to fix the octal number issue. I did so by removing the math and using string concatenation.
if { ([lindex $l 0] eq "Saturday") && ([lindex $l 1] >= 08.) && ([lindex $l 1] < 09.) } { ....
if { ([lindex $l 0] eq "Saturday") && ([format "%g" [lindex $l 1]] >= 😎 && ([format "%g" [lindex $l 1]] < 9) } { ....
- How about this:
set cur_time "[lindex $l 1][lindex $l 2]"
- Tim_Moomaw_9220
Nimbostratus
This one appears to be working correctly:
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects