From 905cda43bef61bfd6569ae37790f92c4e303c85b Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Thu, 21 Mar 2024 18:01:06 +0800 Subject: [PATCH] Optimizing scripts --- scripts/lib/util.sh | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 644565e82..89408a61b 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -2846,26 +2846,7 @@ function openim::util::check_process_names_for_stop() { } -function openim::util::find_process_ports1() { - local process_path="$1" - if [[ -z "$process_path" ]]; then - echo "Usage: find_process_ports /path/to/process" - return 1 - fi - - local protocol_ports="" - lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f $process_path)" | awk '{print $9, $8}' | while read line; do - local port_protocol=($line) - local port=${port_protocol[0]##*:} - local protocol=${port_protocol[1]} - protocol_ports="${protocol_ports}${protocol} ${port}, " - echo "Process $process_path is listening on port $port with protocol $protocol" - done - - protocol_ports=${protocol_ports%, } - echo echo "Process $process_path is listening on protocol & port $protocol_ports " -} function openim::util::find_process_ports() { local process_path="$1" @@ -2880,12 +2861,11 @@ function openim::util::find_process_ports() { local port=${port_protocol[0]##*:} local protocol=${port_protocol[1]} protocol_ports="${protocol_ports}${protocol} ${port}, " - echo "Process $process_path is listening on port $port with protocol $protocol" + done < <(lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f "$process_path")" | awk '{print $9, $8}') protocol_ports=${protocol_ports%, } - echo "Process $process_path is listening on protocol & port $protocol_ports " - + echo "Process $process_path is listening on protocol & port: $protocol_ports " } @@ -2893,9 +2873,6 @@ function openim::util::find_process_ports() { - - - function openim::util::find_ports_for_all_services() { local services=("$@") for service in "${services[@]}"; do @@ -2907,8 +2884,6 @@ function openim::util::find_ports_for_all_services() { - - if [[ "$*" =~ openim::util:: ]];then eval $* fi