![即使脚本成功运行,仍会显示错误状态](https://linux22.com/image/1183735/%E5%8D%B3%E4%BD%BF%E8%84%9A%E6%9C%AC%E6%88%90%E5%8A%9F%E8%BF%90%E8%A1%8C%EF%BC%8C%E4%BB%8D%E4%BC%9A%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF%E7%8A%B6%E6%80%81.png)
#!/bin/sh
serverStatus=$(ps aux | grep server1 -c)
serverStop='/server/myscripts/stopServer.sh server1'
serverStart='/server/myscripts/startServer.sh server1'
$serverStop
sleep 60
echo "$serverStatus"
if [ $serverStatus -ne 2 ]
then
echo 'Alert: App Server1 is down'
$serverStart
else
echo 'Alert: App Server1 is up and running'
fi
输出:
ADMU0116I: Tool information is being logged in file
/server/myscripts/logs/server1/stopServer.log
ADMU0128I: Starting tool with the server profile
ADMU3100I: Reading configuration for server: server1
ADMU3201I: Server stop request issued. Waiting for stop status.
ADMU4000I: Server server1 stop completed.
2
Alert: App Server1 is up and running
输出应该是:
ADMU0116I: Tool information is being logged in file
/server/myscripts/logs/server1/stopServer.log
ADMU0128I: Starting tool with the server profile
ADMU3100I: Reading configuration for server: server1
ADMU3201I: Server stop request issued. Waiting for stop status.
ADMU4000I: Server server1 stop completed.
1
Alert: App Server1 is down