#!/bin/sh
#this checks the /usr tree for I/O errors
if [ ! -e /etc/burnin_on ] 
then
	exit
fi
NZIO="`ps -ef | grep zioerror | grep -v grep | wc -l`"
if [ $NZIO -gt 3 ]
then
    exit
fi
#ls -lR /usr | grep 'Input/output error'
#find /usr -mount -type f -depth -exec ls -l {} \; | grep 'Input/output error'
find /usr \( -path '/usr/local' \) -prune -o -type f -exec ls -l {} \; | grep 'Input/output error'
if [ -e /etc/bonnie.conf ] 
then
    BONNIEFILE="`cat /etc/bonnie.conf`"
    FIRSTDATA=""
    SECONDDATA=""
    for line in $BONNIEFILE
    do
	TYPE="$(echo $line | cut -d ':' -f1)"
        BDIR="$(echo $line | cut -d ':' -f2)"
	BSIZE="$(echo $line | cut -d ':' -f3)"
        if [ "$TYPE" = "sys" ] 
        then
	    SYSDIR="$BDIR"
        fi
        if [ "$TYPE" = "data" ]
	then
	    if [ "$FIRSTDATA" = "" ]
	    then
		FIRSTDATA="$BDIR"
	    else
		SECONDDATA="$BDIR"
            fi
        fi
    done
else
	echo "/etc/bonnie.conf not found" 
fi

if [ -d $FIRSTDATA/syscollect ]
then 
    SYSLS="`ls $FIRSTDATA/syscollect`"
    if [ "$SYSLS" != "" ] 
    then
	ls -lR $FIRSTDATA/* | grep 'Input/output error'
        if [ -e $SYSDIR ]
	then
	    if [ -e $SYSDIR/syscollect ]
	    then
                rm -rf $SYSDIR/syscollect/*
		cp -pr $FIRSTDATA/syscollect/* $SYSDIR/syscollect
	        ls -lR $SYSDIR/* | grep 'Input/output error'
            else
		mkdir $SYSDIR/syscollect
            fi
        fi
        if [ "$SECONDDATA" != "" ] && [ -e $SECONDDATA ]
	then
	    if [ -e $SECONDDATA/syscollect ]
	    then
		rm -rf $SECONDDATA/syscollect/*
		cp -pr $FIRSTDATA/syscollect/* $SECONDDATA/syscollect
                ls -lR $SECONDDATA/* | grep 'Input/output error'
            else
                 mkdir $SECONDDATA/syscollect
            fi
        fi
    fi
fi


