mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-11 01:32:11 +08:00
Script Refactoring
This commit is contained in:
parent
66a676fdf3
commit
4920b20d5a
@ -2850,15 +2850,17 @@ check_binary_ports() {
|
||||
# Check for listening ports using lsof
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq)
|
||||
# Append found ports to the ports variable, followed by a space
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq | tr '\n' ' ')
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq)
|
||||
# Append found ports to the ports variable, followed by a space
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq | tr '\n' ' ')
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove duplicate ports if any
|
||||
ports=$(echo "$ports" | uniq)
|
||||
# Remove trailing spaces and duplicate ports if any
|
||||
ports=$(echo "$ports" | xargs | tr ' ' '\n' | uniq | tr '\n' ' ')
|
||||
|
||||
if [ -z "$ports" ]; then
|
||||
echo "$binary_name is not listening on any ports."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user