以下代码的目的是检查JBoss的状态,while循环迭代直到JBoss状态变为“DOWN'州。 `
JBOSS_ROOT=/opt/app/jboss/jboss.sh
time=1
while [ $JBOSS_ROOT status | egrep -nq "DOWN" ]
do
echo "JBoss stooping, please wait ......."
sleep 1m
if [ $time -gt 6 ]
then
echo "Something went wrong.. it's been running more than 5 minutes, please check JBoos server log and deployments"
exit
fi
time=$(expr "$time" + 1)
done
echo "JBoss stopped"
`
$JBOSS_ROOT status returns "JBoss DOWN" if JBoss in down( stop position).
$ JBOSS_ROOT状态返回" JBoss(pid:32627)正在运行"如果JBoss在运行(开始位置)。
在while循环中抛出错误。说./stop.sh:第5行:[:缺失]'
答案 0 :(得分:0)
同时抛出的错误是因为bash不允许在内部管道
用
替换while [ $JBOSS_ROOT status | egrep -nq "DOWN" ]
while [ $($JBOSS_ROOT status | egrep -nq "DOWN") ]
JBOSS_ROOT=/opt/app/jboss/jboss.sh
time=1
while [ $JBOSS_ROOT status | egrep -nq "DOWN" ]
do
echo "JBoss stooping, please wait ......."
sleep 1m
if [ $time -gt 6 ]
then
echo "Something went wrong.. it's been running more than 5 minutes, please check JBoos server log and deployments"
exit
fi
((time=$time+1))
done
echo "JBoss stopped"
同样time=$(expr "$time" + 1)
无法正常工作time
的价值为1+1
。
您可以使用((time=$time+1))
来评估算术表达式。