![](/img/trans.png)
[英]In my shell script, how can I make the sound stop playing when my charger is plugged in?
[英]How can I make my shell script detect a state change across multiple invocations?
我正在使用以下“腳本”來監視服務器上的端口:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.