The following script checks the last line of a file to see if it has finished the log file or not. It then reports this a part of a simple report. I can't figure out why it's not working:
#find the last file in the directory and remove the .log suffix, for the report
current=`ls -rt1 | tail -1 | cut -d. -f1`
#put the .log suffix back on for following processing
current2=`tail -1 $current.log`
grep "successfully" $current2 > /dev/null 2>&1
if [ $? = 0 ]
then
lastfile=" has completed"
fi
grep "Session run terminated" $current2 > /dev/null 2>&1
if [ $? = 0 ]
then
lastfile=" was terminated by user"
else
lastfile=" is still running"
fi
Depending on the last line of the file the variable $lastfile will return a different value. Why doesn't this work?
Also some files when still running have a blank line on the last line. How do you check for this..is it like "^$" ?
cheers
simmo
#find the last file in the directory and remove the .log suffix, for the report
current=`ls -rt1 | tail -1 | cut -d. -f1`
#put the .log suffix back on for following processing
current2=`tail -1 $current.log`
grep "successfully" $current2 > /dev/null 2>&1
if [ $? = 0 ]
then
lastfile=" has completed"
fi
grep "Session run terminated" $current2 > /dev/null 2>&1
if [ $? = 0 ]
then
lastfile=" was terminated by user"
else
lastfile=" is still running"
fi
Depending on the last line of the file the variable $lastfile will return a different value. Why doesn't this work?
Also some files when still running have a blank line on the last line. How do you check for this..is it like "^$" ?
cheers
simmo