This script checks the log file for timeouts

Code:
#!/bin/ksh
##################################################################################################
#
# This script checks the log file for timeouts #
##################################################################################################

TIMEOUT=`tail -5000 /dir1/logs/logfile.log | grep “has timed out and is not currently tradeable” | tail -1`;

echo ${TIMEOUT};

if [ ! -z ${TIMEOUT} ]; then
echo “Timeout Alert”;
else
echo “No Timeouts”;

————

TIMEOUT=`tail -5000 /dir1/logs/logfile.log | grep “has timed out and is not currently tradeable” | tail -1`;
echo ${TIMEOUT};
[[ ! -z ${TIMEOUT} ]] && echo “Timeout Alert” || echo “No Timeouts”

———————
You can also do this:

Code:
if TIMEOUT=$(tail -5000 /dir1/logs/logfile.log | grep “has timed out and is not currently tradeable” | tail -1)
then
echo “Timeout Alert”
else
echo “No Timeouts”
fi

if you need the TIMEOUT variable afterwards, or

Code:
if tail -5000 /dir1/logs/logfile.log | grep -q “has timed out and is not currently tradeable”
then
echo “Timeout Alert”
else
echo “No Timeouts”
fi

if you don’t need the variable..

==
Edit: The second case will work, but the first will not because of the tail -1 command which will return 0 even if there is no match

Tags: , , , , ,