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]]
29 Replies
- Tim_Moomaw_9220
Nimbostratus
Also receive this message.
TCL error: m-window-test HTTP_REQUEST - cant use invalid octal number as operand of * while executing expr {[lindex $l 1] *100} - hwidjaja_37598
Altostratus
Try this workaround out:
Use this: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]
Replacing this: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]]
It looks like the split from clock produces invalid octal value in Tcl (eg. 08 and 09).
Any solution without regex or correction are welcome - 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.
So if you replace %H with %k:
Hour in 24-hour format, without leading zeros (0 - 23).
Per the clock man page (Click here), it doesn't look like there is an option for minutes without the leading zero. You could manually strip them using string trimleft:
string trimleft 0000123 0
123
Aaron - 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.
Aaron - Tim_Moomaw_9220
Nimbostratus
Great idea Aaron! Not quite there yet though. Sorry to be a pest.....
I haven't tried modifying to fix the minutes yet - 1 thing at a time.
%k and %l give the same error.
TCL error: m-window-test HTTP_REQUEST - cant use empty string as operand of * while executing expr {[lindex $l 1] *100}
Current rule:
when HTTP_REQUEST {
Change the following to set schedule
set start_time "200";
set end_time "900";
set day "Monday";
set l [split [clock format [clock seconds] -format {%A %k %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 200 content " Stuff
}
} - Tim_Moomaw_9220
Nimbostratus
Aaron,
Thanks again. I will definitely give this a try..... tomorrow morning. Alas, we have no test box - I can only test this before 9:59 am. - 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.
when HTTP_REQUEST {
set l [split [clock format [clock seconds] -format {%A %H}] " "]
if { ([lindex $l 0] eq "Saturday") &&
([lindex $l 1] >= 02) &&
([lindex $l 1] < 06) } {
HTTP::respond 200 content " -snip- Maintenance
text=800517>
- snip - is temporarily unavailable.- snip - will be available again at 6:00am.
We are sorry for any inconvenience. "
}
}
This rule won't even compile if a "08" or "09" is used, but again, I don't need it to at the moment.
Thanks to all for the suggestions. If you have additional suggestions I greatly appreciate it! - 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.
As for your iRule, that looks great. If you want to support 08 or 09 in the morning, you can do so by appending a period after the value
So, this theoretically should work:if { ([lindex $l 0] eq "Saturday") && ([lindex $l 1] >= 08.) && ([lindex $l 1] < 09.) } { ....
I'm not sure if this is the "best" way to do it, but it does seem to work.
Another option would be to use the "format" command on the lindex command values to convert the values to a number with "g". If you go that route, you'll want to remove the leading zero from your comparisonif { ([lindex $l 0] eq "Saturday") && ([format "%g" [lindex $l 1]] >= 😎 && ([format "%g" [lindex $l 1]] < 9) } { ....
Lots of ways to go about it. Glad to see it's working for you though!
-Joe - How about this:
set cur_time "[lindex $l 1][lindex $l 2]"
I think that is definitely better than string commands or regular expressions.
I updated the tech tip with this solution btw B-).
-Joe - Tim_Moomaw_9220
Nimbostratus
This one appears to be working correctly:
if { ([lindex $l 0] eq "Saturday") &&
([format "%g" [lindex $l 1]] >= 8) &&
([format "%g" [lindex $l 1]] < 9) } {
....
This one still gives an octal number error:
if { ([lindex $l 0] eq "Saturday") &&
([lindex $l 1] >= 08.) &&
([lindex $l 1] < 09.) } {
....
I haven't had time to play with this one:
set cur_time "[lindex $l 1][lindex $l 2]"
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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