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 
hades
  • 4,294
  • 9
  • 46
  • 71

1 Answers1

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.

Community
  • 1
  • 1
tripleee
  • 175,061
  • 34
  • 275
  • 318