checkPort.sh
This commit is contained in:
parent
d92fadf707
commit
27ee15522b
41
checkPort.sh
Executable file
41
checkPort.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function checkPort()
|
||||||
|
{
|
||||||
|
ip_address=$1
|
||||||
|
port=$2
|
||||||
|
|
||||||
|
# 使用nc命令检测连接
|
||||||
|
nc -zv -w 2 $ip_address $port
|
||||||
|
|
||||||
|
# 检查nc命令的退出状态
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
result=true
|
||||||
|
else
|
||||||
|
result=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 将结果赋值给变量
|
||||||
|
is_active=$result
|
||||||
|
|
||||||
|
# 打印最终结果
|
||||||
|
|
||||||
|
# 根据连接状态输出不同的提示
|
||||||
|
if [ "$is_active" = true ]; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
res=$(checkPort $1 $2)
|
||||||
|
if [ "$res" -eq 1 ]; then
|
||||||
|
echo "service on $1 $2 worked normally"
|
||||||
|
else
|
||||||
|
echo "service port:"$2 " is not actived, try to restart it"
|
||||||
|
#mysql -uroot -pAbcd@1234 -h0.0.0.0 -e "SET GLOBAL lower_case_table_names = 1;"
|
||||||
|
# systemctl restart shadowsocks-libev-server@libev
|
||||||
|
eval $3
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit
|
Loading…
x
Reference in New Issue
Block a user