From ae75708e9237c40453e3fd757831bc392984d2e1 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 6 Mar 2024 15:39:11 +0800 Subject: [PATCH] Optimize script logs --- scripts/lib/util.sh | 56 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 05904198d..765405fed 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -402,34 +402,36 @@ openim::util::check_process_names() { local not_started=() local started=() - # Iterate over each given process name - for process_name in "$@"; do - # Use `pgrep` to find process IDs related to the given process name - local pids=($(pgrep -f $process_name)) - - # Check if any process IDs were found - if [[ ${#pids[@]} -eq 0 ]]; then - not_started+=("$process_name") - else - # If there are PIDs, loop through each one - for pid in "${pids[@]}"; do - local command=$(ps -p $pid -o cmd=) - local start_time=$(ps -p $pid -o lstart=) - local port=$(get_port $pid | tr -d '\n') # Remove newline characters - - # Insert a space at the desired position in the port string - if [[ ! -z $port && $port != "N/A" ]]; then - port="${port:0:4} ${port:4}" # Add a space after the fourth character - fi + # Iterate over each given process name + for process_name in "$@"; do + # Use `pgrep` to find process IDs related to the given process name + local pids=($(pgrep -f $process_name)) + + # Check if any process IDs were found + if [[ ${#pids[@]} -eq 0 ]]; then + not_started+=("$process_name") + else + # If there are PIDs, loop through each one + for pid in "${pids[@]}"; do + local command=$(ps -p $pid -o cmd=) + local start_time=$(ps -p $pid -o lstart=) + local port=$(get_port $pid | tr -d '\n') # Remove any newline characters + + # Add space within port numbers, assuming you need to format them + if [[ ! -z $port && $port != "N/A" ]]; then + # Example formatting: assuming ports are returned as a single long string and you want to separate every 4 characters with a space + port=$(echo "$port" | sed 's/.\{4\}/& /g') + fi + + if [[ -z $port ]]; then + port="N/A" + fi + + started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") + done + fi + done - if [[ -z $port ]]; then - port="N/A" - fi - - started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") - done - fi - done