?
Solved

Tcl script

Posted on 2005-02-27
6
Medium Priority
?
507 Views
Last Modified: 2013-11-22
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
Comment
Question by:wonkdeweck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 25

Expert Comment

by:jrb1
ID: 13425016
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
 

Author Comment

by:wonkdeweck
ID: 13436750
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
 
LVL 25

Expert Comment

by:jrb1
ID: 13436799
Are you trying to fill in 3 variables from your regexp?  I did't think you could do that.
0
 

Author Comment

by:wonkdeweck
ID: 13474597
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 14219788
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Starting up a Project
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question