[PATCH V2] rlWaitForSocket - use ss, fallback to netstat
by Hubert Kario
RHEL-7 doesn't install netstat by default. The minimal install has
`ss' so use it instead. As RHEL-5 doesn't have ss in iproute packge
keep using netstat as a fallback.
Check for aviability of both tools, abort if none is available.
Signed-off-by: Hubert Kario <hkario(a)redhat.com>
---
Previous version had -eq with -nq switched after local ss_path line
src/synchronisation.sh | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/synchronisation.sh b/src/synchronisation.sh
index 15e5602..46a426e 100644
--- a/src/synchronisation.sh
+++ b/src/synchronisation.sh
@@ -469,7 +469,19 @@ rlWaitForSocket(){
esac
rlLogInfo "rlWaitForSocket: Waiting max ${timeout}s for socket \`$socket' to start listening"
- local cmd="netstat -nl | grep -E '$grep_opt' >/dev/null"
+ local ss_path=$(env which ss 2>/dev/null)
+ if [[ $? -eq 0 ]] && [[ -n $ss_path ]]; then
+ # FIXME, should also have sctp, but it is not yet supported by ss
+ local tool="$ss_path -l -n -o -A tcp,udp,unix"
+ else
+ local tool="$(env which netstat 2>/dev/null) -nl"
+ if [[ $? -ne 0 ]]; then
+ rlLogError "rlWaitForSocket: Can't find \`netstat' or \`ss' in system, aborting"
+ return 127
+ fi
+ fi
+
+ local cmd="$tool | grep -E '$grep_opt' >/dev/null"
if [[ ${close:-false} == true ]]; then
__INTERNAL_wait_for_cmd "rlWaitForSocket" "${cmd}" -t $timeout -p $proc_pid -d $delay -r 1
--
1.8.3.1
10 years, 2 months
[PATCH] rlWaitForSocket - use ss, fallback to netstat
by Hubert Kario
RHEL-7 doesn't install netstat by default. The minimal install has
`ss' so use it instead. As RHEL-5 doesn't have ss in iproute packge
keep using netstat as a fallback.
Check for aviability of both tools, abort if none is available.
Signed-off-by: Hubert Kario <hkario(a)redhat.com>
---
src/synchronisation.sh | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/synchronisation.sh b/src/synchronisation.sh
index 15e5602..f61e302 100644
--- a/src/synchronisation.sh
+++ b/src/synchronisation.sh
@@ -469,7 +469,18 @@ rlWaitForSocket(){
esac
rlLogInfo "rlWaitForSocket: Waiting max ${timeout}s for socket \`$socket' to start listening"
- local cmd="netstat -nl | grep -E '$grep_opt' >/dev/null"
+ local ss_path=$(env which ss 2>/dev/null)
+ if [[ $? -ne 0 ]] && [[ -n $ss_path ]]; then
+ local tool="$ss_path -l -n -o -A tcp,udp,unix"
+ else
+ local tool="$(env which netstat) -nl"
+ if [[ $? -ne 0 ]]; then
+ rlLogError "rlWaitForSocket: Can't find \`netstat' or \`ss' in system, aborting"
+ return 127
+ fi
+ fi
+
+ local cmd="$tool | grep -E '$grep_opt' >/dev/null"
if [[ ${close:-false} == true ]]; then
__INTERNAL_wait_for_cmd "rlWaitForSocket" "${cmd}" -t $timeout -p $proc_pid -d $delay -r 1
--
1.8.3.1
10 years, 2 months