#!/bin/bash

source /opt/tool/pvi_test.sh
pvi_init

count=3
for i in `seq $(($count+1))`
do
    #echo "i is $i"
    if [ ! -f "/opt/collect/delSata_$i.log" ]; then
        break
    fi
done

if [ $i -eq $(($count+1)) ]; then 
    rm /opt/collect/delSata_1.log
    i=$count
    for j in `seq $(($count-1))`
    do
        #echo "/opt/log/kmsg_$(($j+1)).log /opt/log/kmsg_$j.log"
        mv /opt/collect/delSata_$(($j+1)).log /opt/collect/delSata_$j.log
    done
fi

date > /opt/collect/delSata_$i.log

dmesg -c >> /dev/null

while [ TRUE ]
do

check_results=`dmesg | grep "ata4.00: disabled"`
if [[ $check_results =~ "ata4.00: disabled" ]] 
then 
    dmesg -c >> /opt/collect/delSata_$i.log
    pvi_current_get Isource
    echo -e "Current after unloading : ${Isource}" >> /opt/collect/delSata_$i.log 
    sync   
fi

sleep 1
done
