From ea6806f1c602c556bb0dd96b43d42e1f99886e42 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 6 Mar 2024 15:45:36 +0800 Subject: [PATCH] Optimize script logs --- scripts/lib/util.sh | 51 ++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 4ca796beb..8903d083e 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -403,34 +403,29 @@ openim::util::check_process_names() { 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 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 + 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) + + # Check if port information was found for the PID + 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