I am just trying to check the alert.log
file, if it is having the word (line? ed.) count greater than 4 and the word Time is there in it, then I will grep
only for Time and it will print the latest timestamp. But if Time is not there, it should print the current date.
I wanted to check the word count and grep criteria in one condition.
if [[ -s "${SCRIPT_PATH}/alert.log" ]]; then
if test `cat alert.log | wc -l` -gt 4 ;
then
if test -s `cat alert.log | grep -i Time`;
then
cat alert.log | tail -r | grep -i Time > latest_time.out
CURRENT_TIMESTAMP=`cat latest_time.out | head -1 | grep "Time:*" | cut -f2 -d":"`
echo $CURRENT_TIMESTAMP
rm alert.log
fi
fi
else
CURRENT_TIMESTAMP=$( date +%Y-%m-%d )
echo $CURRENT_TIMESTAMP
fi
If I execute this script and if alert.log
does not contain the word time, it should print the current timestamp, but it's not working. And when I checked separately, I found that `cat alert.log | wc -l` -gt 4
, this part is not working. What's wrong?