We have encountered some situations on servers (usually when first building them, or when a server is shut down suddenly), where the sar files for a day have incomplete or missing lines of data. In these situations, the sar2ascii script looks for a date string that isn't there, and throws the error "-lt: unary operator expected" because it is comparing a null value. In cases where a sar file is blank, it will continue to compile data, but if a line is corrupt or contains an error message, the script will stop processing.
You can reproduce some of the behavior by creating an empty "sa##" and "sar##" file in /var/log/sa/, then running the sar2ascii script.
One workaround is to delete the corrupt or blank sa/sar file, but we can also easily skip the offending file when running the sar2ascii script.
In latest version of script 2.4.2, the lines are 368-372. I added an extra "if" entry at the top of the statement to check for null values in the date variable, and to skip that iteration of the for loop if you get a null value. You could get fancier, but this fixed the issues we were seeing.
if [ -z "$date" ]; then
echo "Invalid date string $SA_DATE in file, skipping file..."
continue
elif [ $date -lt 100 ]; then
SA_DATE=`echo $SA_DATE | awk -F/ '{ print "20"$3"."$1"."$2 }'`
else
SA_DATE=`echo $SA_DATE | awk -F/ '{ print $3"."$1"."$2 }'`
fi
Oop- should have updated my echo statement. A more informative statement would be:
echo "Invalid date info for $FILE , skipping file..."
Checking...