From eac6b98bac0e157158241ee1d55d375058b375af Mon Sep 17 00:00:00 2001 From: Gardouille Date: Mon, 2 Feb 2015 09:46:12 +0100 Subject: [PATCH] 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). --- dynmotd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynmotd b/dynmotd index bc0a110..666fdd7 100755 --- a/dynmotd +++ b/dynmotd @@ -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} "