mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-10 17:22: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
|
# Check for listening ports using lsof
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
# Linux
|
# 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
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
# macOS
|
# 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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove duplicate ports if any
|
# Remove trailing spaces and duplicate ports if any
|
||||||
ports=$(echo "$ports" | uniq)
|
ports=$(echo "$ports" | xargs | tr ' ' '\n' | uniq | tr '\n' ' ')
|
||||||
|
|
||||||
if [ -z "$ports" ]; then
|
if [ -z "$ports" ]; then
|
||||||
echo "$binary_name is not listening on any ports."
|
echo "$binary_name is not listening on any ports."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user