stop()
{
sh stop.sh
ret_code=$?
<1>echo ret_code is $ret_code
}
once=true
while $once
do
stop & PID=$!
<2>echo ret_code is $ret_code
sleep 2m
<3>echo ret_code is $ret_code
if [ $ret_code == 0 ]
then
break
else
kill $PID
fi
done
ret_code>是0Unix的返回代码改变
ret_code在< 2>不打印
ret_code在< 3>是空白
有人能告诉为什么ret_code值在睡眠命令期间和之后发生变化?
编辑:
我曾尝试另一种方法。它的工作 -
#! /bin/sh
once=true
while $once
do
sh stop.sh & PID=$!
sleep 2m
kill $PID
if [ $? != 0 ]
then
echo stop has completed successfully within the time limit
echo starting ...
sh start.sh
break
fi
done
1)第3行的stop.sh是什么? – 2013-02-28 10:01:09
2)您可以调整回声语句以包含“1.”,“2”并包括脚本的输出吗? – 2013-02-28 10:01:41
@AshBerlin这是另一个实际上停止服务的shell脚本。它通常运行良好,因此rc通常为0.但是有时它会卡住,因此这种复杂的写入方式可能会导致简单的停止/启动过程 – Jay 2013-02-28 13:13:00