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.
wonkdeweckAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jrb1senior developerCommented:
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
jrb1senior developerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.