Menu

#6 Minor fix: error handling when date string in a sar file is null or missing

Unstable_(example)
accepted
nobody
None
5
2013-11-27
2013-11-25
d3
No

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

Discussion

  • d3

    d3 - 2013-11-25

    Oop- should have updated my echo statement. A more informative statement would be:

    echo "Invalid date info for $FILE , skipping file..."

     
  • CemTan

    CemTan - 2013-11-26

    Checking...

     
  • CemTan

    CemTan - 2013-11-26
    • status: open --> pending
     
  • CemTan

    CemTan - 2013-11-27
    • status: pending --> accepted
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.