#!/bin/sh
SUCCESS=0
java -jar sbc.jar &
while [ true ];
do
echo "sleeping"
sleep 5
echo "again"
tail -1 ~/NetBeansProjects/xyz/dist/newlog.log | grep -q "[INFO ] - Stream closed"
if [ $? = 1 ]
then
echo " entered if "
java -jar sbc.jar &
else
echo " did not if "
fi
done
我想使用比$更好的变量?存储前一行的结果,因为我可能不止一次需要它。该脚本旨在检查文件newlog.log
的最后一行是否有特定字符串,然后再次启动sbc.jar
,因为该字符串确认程序已停止。
答案 0 :(得分:1)
将其存储在另一个变量中:
...
tail -1 ~/NetBeansProjects/xyz/dist/newlog.log | grep -q "[INFO ] - Stream closed"
RES=$?
if [ $RES = 1 ]
...