Using `grep+sort+head -n1` instead of `grep -m1` permit, if a port is

listening on multiple interfaces (127.0.0.1:25, 192.168.0.1:25, *:25) to
print the most generic one (*:25).
This commit is contained in:
Jeremy Gardais 2015-02-02 09:46:12 +01:00
parent 566450407e
commit eac6b98bac
1 changed files with 2 additions and 1 deletions

View File

@ -56,7 +56,8 @@ service_info() {
# If a port listen
if (ss -lutn|grep -m1 ":${PORT}" > /dev/null); then
# Example: "tcp/127.0.0.1:25"
MSG="${MSG}${GREEN}$(ss -lutn|grep -m1 ":${PORT}"|awk '{print $1"/"$5}')${RESET} "
#MSG="${MSG}${GREEN}$(ss -lutn|grep -m1 ":${PORT}"|awk '{print $1"/"$5}')${RESET} "
MSG="${MSG}${GREEN}$(ss -lutn|grep ${PORT}|sort|head -n1|awk '{print $1"/"$5}')${RESET} "
else
# Example: "22: NOT LISTENING"
MSG="${MSG}${REDB}${PORT}: NOT LISTENING${RESET} "