Menu

#8 PATCH: Avoiding cat errors for devices that no longer exist

Unstable_(example)
closed
CemTan
None
5
2016-02-05
2016-01-29
d3
No

We have noticed when pre-existing devices have been removed from a server, sar2html will start throwing errors every time it tries to merge new data:

cat: /u003/app/sar2html/sarDATA/sar2html.23601/sar2html/SunOS_9/utweba01.ovnt.com-83d4e0ab/report/d.1--ssd14,t5: No such file or directory

This appears to be from the first 'cat' statement starting at line 596:

SA_REPFILES=`ls $SA_LOC/$SA_HOST/report`
for FILE in $SA_REPFILES; do
    cat $SA_LOC/sar2html.$$/sar2html/$SA_HOST/report/$FILE >> $SA_LOC/$SA_HOST/report/$FILE
    cat $SA_LOC/$SA_HOST/report/$FILE | sort | uniq > $SA_LOC/$SA_HOST/report/$FILE.$$
    mv -f $SA_LOC/$SA_HOST/report/$FILE.$$ $SA_LOC/$SA_HOST/report/$FILE
done

As I understand, it uses the existing files in a host's 'report' directory as a guide for what to import from new sar2ascii reports. If sar is no longer collecting stats on that host, there won't be a corresponding file in the new report, so the first cat throws an error because there is nothing to import for that device.

You can reproduce by removing a physical device from a host and then running another sar2ascii update and merge.

You can avoid these errors with a quick ' if ' statement surrounding the 'cat' and 'move' operations, to check if the file exists first. I tested on Redhat 6 and it seemed to work.

SA_REPFILES=`ls $SA_LOC/$SA_HOST/report`
for FILE in $SA_REPFILES; do
    if [ -f $SA_LOC/sar2html.$$/sar2html/$SA_HOST/report/$FILE ]; then
        cat $SA_LOC/sar2html.$$/sar2html/$SA_HOST/report/$FILE >> $SA_LOC/$SA_HOST/report/$FILE
        cat $SA_LOC/$SA_HOST/report/$FILE | sort | uniq > $SA_LOC/$SA_HOST/report/$FILE.$$
         mv -f $SA_LOC/$SA_HOST/report/$FILE.$$ $SA_LOC/$SA_HOST/report/$FILE
    fi
done

Discussion

  • CemTan

    CemTan - 2016-02-01

    Current code does not take device removal into account.
    Adding new device to physical server would not be a problem under this circumstances but device removal causes the problem you stated appearently.
    It seems the best way fixing the issue is to check if file exists or not. So I accept your workaround and will add it to next release.
    Thanks for your effort and interest.

     
  • CemTan

    CemTan - 2016-02-01
    • status: open --> accepted
    • assigned_to: CemTan
     
  • CemTan

    CemTan - 2016-02-05
    • status: accepted --> closed
     

Log in to post a comment.