gpt4 book ai didi

linux - 如何让我的 shell 脚本检测到多次调用的状态变化?

转载 作者:太空宇宙 更新时间:2023-11-04 10:19:40 25 4
gpt4 key购买 nike

我正在使用以下“脚本”来监控服务器上的端口:

l_TELNET=`echo "quit" | telnet server.domain.tld 12345 | grep "Escape character is"`
if [ "$?" -ne 0 ]; then
echo "Connection to $SERVER on port $PORT failed"
#Something happens here if Service (port) down
exit 1
else
#Something happens here if Service (port) up
exit 0
fi

我如何修改它以仅在第一次检测到服务关闭时执行“服务关闭”部分(直到它下一次备份),而不是每五分钟执行一次服务继续下降?

最佳答案

使用临时文件怎么样?

l_TELNET=`echo "quit" | telnet server.domain.tld 12345 | grep "Escape character is"`
if [ "$?" -ne 0 ]; then
if [ ! -f /tmp/12345down]; then
echo "Connection to $SERVER on port $PORT failed"
#Something happens here if Service (port) down
touch /tmp/12345down
exit 1
fi
exit 0
else
#Something happens here if Service (port) up
if [ -f /tmp/12345down]; then
rm -f /tmp/12345down
fi
exit 0
fi

关于linux - 如何让我的 shell 脚本检测到多次调用的状态变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com