From f04c3ad79ad7e881463add995da2b20abe41afbb Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Thu, 23 Nov 2023 16:03:30 +0800 Subject: [PATCH] checkports --- scripts/check_ports.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/check_ports.sh b/scripts/check_ports.sh index c08cc4be..c110697d 100644 --- a/scripts/check_ports.sh +++ b/scripts/check_ports.sh @@ -14,7 +14,6 @@ # $ sudo bash check_ports.sh --port 9001,9001 # ============================================================================== - # 获取参数值 while [[ $# -gt 0 ]]; do case $1 in @@ -29,15 +28,18 @@ while [[ $# -gt 0 ]]; do done check_ports() { + local used_ports=() for port in "${ports[@]}"; do if ss -tuln | grep ":$port " >/dev/null; then - echo "Port $port is in use!" - return 1 + used_ports+=("$port") fi done - echo "All ports are available" - return 0 + if [ ${#used_ports[@]} -eq 0 ]; then + echo "0" + else + IFS=','; echo "${used_ports[*]}" + fi } -check_ports +check_ports \ No newline at end of file