0

i have a large log file A.log, i want to grep ONE CERTAIN STRING from the last 10 lines and compare to a variable (FTP_SUCCESS_MSG), how can i do that?

something like:

logs='/tmp/A.log'
FTP_SUCCESS_MSG="226 Transfer complete"
if [tail -10 $logs == $FTP_SUCCESS_MSG] ; 
then 
    echo "Success"  
else
    echo "Failed"
    exit 1
fi 

1 Answer 1

1
if tail -10 "$logs" | grep -Fq "$FTP_SUCCESS_MSG" ;  then ...

Notice how [ is not present in the condition (and if it were, it would require non-optional spaces on both sides).

Notice also how variable interpolations are in double quotes unless you require the shell to tokenize the value and perform wildcard expansion on the tokens.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.