mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-24 10:17:15 +08:00
checkports
This commit is contained in:
parent
1bfba4ed7e
commit
f04c3ad79a
@ -14,7 +14,6 @@
|
|||||||
# $ sudo bash check_ports.sh --port 9001,9001
|
# $ sudo bash check_ports.sh --port 9001,9001
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
|
|
||||||
# 获取参数值
|
# 获取参数值
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
@ -29,15 +28,18 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
check_ports() {
|
check_ports() {
|
||||||
|
local used_ports=()
|
||||||
for port in "${ports[@]}"; do
|
for port in "${ports[@]}"; do
|
||||||
if ss -tuln | grep ":$port " >/dev/null; then
|
if ss -tuln | grep ":$port " >/dev/null; then
|
||||||
echo "Port $port is in use!"
|
used_ports+=("$port")
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "All ports are available"
|
if [ ${#used_ports[@]} -eq 0 ]; then
|
||||||
return 0
|
echo "0"
|
||||||
|
else
|
||||||
|
IFS=','; echo "${used_ports[*]}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_ports
|
check_ports
|
Loading…
Reference in New Issue
Block a user