Optimizing scripts

pull/2100/head
skiffer-git 2 years ago
parent c4e8b796ac
commit 90fd2fe84d

@ -2846,7 +2846,6 @@ function openim::util::check_process_names_for_stop() {
} }
function openim::util::find_process_ports() { function openim::util::find_process_ports() {
local process_path="$1" local process_path="$1"
if [[ -z "$process_path" ]]; then if [[ -z "$process_path" ]]; then
@ -2854,24 +2853,29 @@ function openim::util::find_process_ports() {
return 1 return 1
fi fi
local pids=$(pgrep -f "$process_path")
if [[ -z "$pids" ]]; then
echo "No running process found for $process_path."
return 1
fi
local ports_info="" local ports_info=""
lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f $process_path)" | awk '{print $9, $8}' | while read line; do while read -r line; do
local port_protocol=($line) local port_protocol=($line)
local port=${port_protocol[0]##*:} local port=${port_protocol[0]##*:}
local protocol=${port_protocol[1]} local protocol=${port_protocol[1]}
ports_info+="$port($protocol) " ports_info+="$port($protocol) "
done done < <(lsof -nP -iTCP -iUDP | grep LISTEN | grep -E "$(echo $pids | sed 's/ /\\|/g')")
if [[ -z "$ports_info" ]]; then
echo "No ports found for process $process_path."
else
if [[ -n "$ports_info" ]]; then
echo "Process $process_path is listening on ports: $ports_info" echo "Process $process_path is listening on ports: $ports_info"
else
echo "No ports found for process $process_path."
fi fi
} }
function openim::util::find_ports_for_all_services() { function openim::util::find_ports_for_all_services() {
local services=("$@") local services=("$@")
for service in "${services[@]}"; do for service in "${services[@]}"; do

Loading…
Cancel
Save