0

I am new to scripting

Can anyone help me with what is wrong with my below script. I am getting an error.

if `tail -2 jeevagan/sample/logs.txt | head -1 | grep "Start Outputing Report"` = TRUE && `tail -1 jeevagan/sample/logs.txt | grep "Start Outputing Report"` = TRUE

then
        echo "report error"
else
        echo "report good"
fi

In the logs file, i have logs such as below:

2016-04-07 06:57:36,248 INFO : Finished Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 07:06:52,812 INFO : Start Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 06:52:56,451 INFO : Finished Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 06:52:56,451 INFO : Finished Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 07:06:52,812 INFO : Start Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 07:06:52,812 INFO : Start Outputing Report:, Format:EXCEL, Locale: en_IN
2016-04-07 07:06:52,812 INFO : Start Outputing Report:, Format:EXCEL, Locale: en_IN
0

1 Answer 1

1

From 'man bash' on my solaris system:

command1 && command2
command2 is executed if, and only if,  command1  returns  an
exit status of zero.

To examine the exit status run a command, then

echo $?

So

tail -2 log.txt | head -1 | grep "Start Outputing Report"

Returns 0

So you can string them together like so

tail -2 log.txt | head -1 | grep "Start Output" && tail -1 log.txt | grep "Start Output" && echo "report error"

or script them out something like

tail -2 log.txt | head -1 | grep "Start Output" && tail -1 log.txt | grep "Start Output" 

return=$?

if [[ $return == 0 ]]; then
    echo "report error"
else
    echo "report good"
fi
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.