I have tried to search process id i-e 6762 stored in a variable say buffer
nohup tcpdump -ni eth0 -s0 2>&1
It is important to put spaces and braces in in Tcl because each word to a command needs to be properly separated from all the others and end-of-line signals end-of-command unless you quote or escape it.
Thus, your code:
foreach line [split $buffer "\n"]{
if {[regexp {\[\d\]\s+(\d+)}$line junk pid]}
break
}
That has a problem in that there's no space between ]
and {
on the first line, a problem in that there's no space between }
and $
on the second line, and a problem that there's nothing to make the third line associated with the second. Let's write it to be conventional Tcl:
foreach line [split $buffer "\n"] {
if {[regexp {\[\d\]\s+(\d+)} $line junk pid]} {
break
}
}
I've changed almost nothing; just added some spaces and some braces.