尽可能简单。
我希望这个脚本在名为“out.log”的日志文件中捕获一行“hello”。我遇到的问题是,即使我知道日志文件包含,它总是得到“echo expression评估为假”作为输出我想要的线
#!/bin/bash
SERVICE_HOME="home/username/Desktop/SMX3test"
CURRENT_USER=`whoami`
start=0
NULLPOINT=out.log
OUT=hello
LINES=20
if [ 'tail -n $LINES $NULLPOINT | grep hello' = "$OUT" ];
then
echo expression evaluated as true
else
echo expression evaluated as false
fi
exit $start
有小费或解决方案的任何人吗?
/呼
#我知道了!##
#最终代码:
#!/bin/bash
############################
# Phew's Start/stop script #
############################
SERVICE_HOME="opt/data/log/ls/smx3/"
CURRENT_USER=`whoami`
start=0
NULLPOINT=servicemix.log
OUT=NullPointerException
LINES=20
REV=$(tail -n $LINES $NULLPOINT | grep NullPointerException)
if [ $REV = "$OUT" ];
then
/etc/init.d/ls-smx3 stop && sleep 300 && /etc/init.d/ls-smx3 start
else
echo "Allting är okej!"
fi
exit $start
#####
#END#
#####