Optimize script logs

pull/2007/head
skiffer-git 2 years ago
parent db0ae689ae
commit 071937de50

@ -402,32 +402,35 @@ openim::util::check_process_names() {
local not_started=() local not_started=()
local started=() local started=()
# Iterate over each given process name # Iterate over each given process name
for process_name in "$@"; do for process_name in "$@"; do
# Use `pgrep` to find process IDs related to the given process name # Use `pgrep` to find process IDs related to the given process name
local pids=($(pgrep -f $process_name)) local pids=($(pgrep -f $process_name))
# Check if any process IDs were found # Check if any process IDs were found
if [[ ${#pids[@]} -eq 0 ]]; then if [[ ${#pids[@]} -eq 0 ]]; then
not_started+=("$process_name") not_started+=("$process_name")
else else
# If there are PIDs, loop through each one # If there are PIDs, loop through each one
for pid in "${pids[@]}"; do for pid in "${pids[@]}"; do
local command=$(ps -p $pid -o cmd=) local command=$(ps -p $pid -o cmd=)
local start_time=$(ps -p $pid -o lstart=) local start_time=$(ps -p $pid -o lstart=)
local port=$(get_port $pid | tr -d '\n') # Remove newline characters local port=$(get_port $pid | tr -d '\n') # Remove newline characters
# Ensure port information is followed by a space for separation # Insert a space at the desired position in the port string
if [[ -z $port ]]; then if [[ ! -z $port && $port != "N/A" ]]; then
port="N/A " port="${port:0:4} ${port:4}" # Add a space after the fourth character
else fi
port="$port " # Add a trailing space for separation
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
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
done
fi
done
# Print information # Print information

Loading…
Cancel
Save