Forum Discussion
Irule syntax issue : missing a script
Hi, I'm having the error message on line 18 "missing a script". What i'm trying to do with this iRule is to append one or two "0" when the $fract value contains only two or one digit, whereas most of the time is has 3 digits.
Any help so much welcome.
when HTTP_REQUEST {
set secs [clock seconds]
set msec [clock clicks -milliseconds]
set base [expr { $secs * 1000 } ]
set fract [expr { $msec - $base }]
log local0. "step_1 $fract"
if {$fract >= 1000 } { set diff [expr { $fract / 1000 }] incr secs $diff incr fract [expr { -1000 * $diff }]}
log local0. "step_2 $fract"
if {[$fract matches_regex "\d\d"]} append fract 0 elseif {$fract matches_regex {/\d}} append fract 00
log local0. "Timestamp with milliseconds is $secs.$fract" }
9 Replies
- What_Lies_Bene1
Cirrostratus
Perhaps it's the formatting but which line is 18 please?
- Thomas_Gobet
Nimbostratus
It's a problem on formatting.
After each if condition you have to add curly brackets.
if { your condition } { What_you_want_to_do } else { other_condition } { actions }- Aurel
Cirrus
That's it Thomas. I forgot the curly braces for the "What i want to do". A big thank you ! Strange that the irule editor said nothing about it, yet he's quite talkative usually.
- Thomas_Gobet_91
Cirrostratus
It's a problem on formatting.
After each if condition you have to add curly brackets.
if { your condition } { What_you_want_to_do } else { other_condition } { actions }- Aurel
Cirrus
That's it Thomas. I forgot the curly braces for the "What i want to do". A big thank you ! Strange that the irule editor said nothing about it, yet he's quite talkative usually.
- Thomas_Gobet
Nimbostratus
I mean with you code :
if {[$fract matches_regex "\d\d"]} { append fract 0 } elseif {$fract matches_regex {/\d} } { append fract 00 } - cjunior
Nacreous
I just test the syntax and it works. Remember: Trim the end of each line, indent the beginning for best pratices and write the conditions with curly braces. To paste the code on this forum, start each line with {tab} character when HTTP_REQUEST { set secs [clock seconds] set msec [clock clicks -milliseconds] set base [expr { $secs * 1000 } ] set fract [expr { $msec - $base }] log local0. "step_1 $fract" if {$fract >= 1000 } { set diff [expr { $fract / 1000 }] incr secs $diff incr fract [expr { -1000 * $diff }] } log local0. "step_2 $fract" if {[$fract matches_regex "\d\d"]} { append fract 0 } elseif {$fract matches_regex {/\d} } { append fract 00 } log local0. "Timestamp with milliseconds is $secs.$fract" } - Aurel
Cirrus
I even found a way to do the job i wanted within one single line : set timestamp [format "%d%03d000" $timestamp $fract]
Thanks to a colleague who speaks fluently perl, tcl among others.
- What_Lies_Bene1
Cirrostratus
Awesome.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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