Currently I'm using netstat for this:
if netstat -an | grep ESTABLISHED | grep $address:$port > /dev/null; then
# command
fi
Is there a more elegant solution?
|
Currently I'm using netstat for this:
Is there a more elegant solution? |
|||
|
As far as elegance is concerned, I'd modify two things in your command:
|
|||||||||||||||
|
|
If you need more information:
|
|||
|
|
|
with
|
||||
|
|
|
That works well enough for now, for Linux. On other UNIX systems (the ones I have my hands on are Mac OS X and Solaris) the port is separated by And this will most likely fail for any IPv6 connection. |
|||
|
|
|
You can use |
|||
|
|
grep -qinstead of sending stdout to /dev/null. – Chris Down Sep 19 '11 at 16:05grepand IP-addresses are pitfall, since usual notation for IP-addresses has dots inside. See my comments: unix.stackexchange.com/questions/21020/… P. S. I'd mark as answer this one: unix.stackexchange.com/a/36354/6622 – poige Apr 14 '12 at 16:33