Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

Tcl script

Dear Experts,

I have a script written in Tcl (.swt) to get the Round Trip Time by using ping command and parse the data in csv format (only the minimum,average and maximum). My script looks like below:

----Script Begin----
#EXEC
set pc 10 (-- counter)
set ps 56 (-- data size)
set host [lindex $argv 0]
set logf [open [lindex $argv 1] a]

while {1} {

set mydate [clock format [clock seconds] -format "%d/%m/%Y"]
set mytime [clock format [clock seconds] -format "%H:%M:%S"]
catch {exec ping -s $host $ps $pc} rc
regexp {.*min/avg/max = (.*/.*/.*} $rc all min max avg
puts $logf "\"$mydate\",\"$mytime\",\"$host\",\"OnlyInstance\",\"Latency\",,$avg,$max,\"$mytime\",$min,\"$mytime\",\"TRF\""

flush $logf

after [expr 984*60*10]

}

close $logf
---Script End---

But everytime i tried to run the script, i got this error messages:

couldn't compile regular expression pattern: parentheses () not balanced
    while executing
"regexp {.*min/avg/max = (.*/.*/.*} $rc min max avg"
    ("while" body line 8)
    invoked from within
"while {1} {

set mydate [clock format [clock seconds] -format "%d/%m/%Y"]
set mytime [clock format [clock seconds] -format "%H:%M:%S"]
#catch {exec pi..."
    (file "scLatency.swt" line 9)

Any idea on how to solve this problem? Thank you very much.

reg,
Derix Suartyo.
0
wonkdeweck
Asked:
wonkdeweck
  • 2
  • 2
1 Solution
 
jrb1Commented:
In this line:

regexp {.*min/avg/max = (.*/.*/.*} $rc all min max avg

Are you actually looking for a "(" in the regular expression?  If so, you need to escape it:

regexp {.*min/avg/max = \(.*/.*/.*} $rc all min max avg
0
 
wonkdeweckAuthor Commented:
Hi jrb1,

Thank you very much for your prompt reply. I have modified my script as shown below:

regexp {.*min/avg/max = \(.*/.*/.*} $rc all min max avg

but unfortunately, i got different error message:
can't read "avg": no such variable
    while executing
"puts $logf "\"$mydate\",\"$mytime\",\"$host\",\"OnlyInstance\",\"Latency\",,$avg,$max,\"$mytime\",$min,\"$mytime\",\"TRF\"""
    ("while" body line 9)
    invoked from within
"while {1} {

I tried to modify the regular expression but the problem remains. Any other idea? Thanks.

reg,
Derix Suartyo.
0
 
jrb1Commented:
Are you trying to fill in 3 variables from your regexp?  I did't think you could do that.
0
 
wonkdeweckAuthor Commented:
Dear Admin,

Please kindly close this case as i have found the solution.

to jrb1: thank you for your comment, i managed to grep the data using regexp command, the syntax look like this:
regexp {.*min/avg/max = (.*)/(.*)/(.*)} $rc all min avg max

reg,
Derix Suartyo.
0
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now