NSLU2-Linux
view · edit · print · history
#!/bin/sh
logfile=/var/log/ex-hdd-power
devicelink=/dev/freecom
mountdir=freecom

if test -e $devicelink
then
device=`/bin/ls -l $devicelink | awk '{print $10}'`
idle_state=`cat "/tmp/diskstate_$device"`
state=`grep $device /proc/diskstats`

if [ "$state" = "$idle_state" ]
then
exit 0

else

 echo "-------`date`-------" >> $logfile

 mountpoints=$(/bin/grep $mountdir /etc/mtab | awk '{print $2}')
 if test "$mountpoints"
   then
   echo "disk mounted" >> $logfile
 else
   echo "disk not in use, power down." >> $logfile
   echo "`sg_start --stop $devicelink`" >> $logfile
   idle_state=`grep $device /proc/diskstats`
   echo "$idle_state" > "/tmp/diskstate_$device"
   exit 0
 fi


 for point in $mountpoints
 do
   probe=`fuser -c $point`
   if test "$probe"
     then
     echo "disk in use" >> $logfile
     exit 0
   fi
 done

 echo "filesystems not in use, power down."        >> $logfile
 echo "`sg_start --stop $devicelink`" >> $logfile
 idle_state=`grep $device /proc/diskstats`
 echo "$idle_state" > "/tmp/diskstate_$device"
fi
fi
#end
  1. !/bin/sh

logfile=/var/log/ex-hdd-power devicelink=/dev/freecom mountdir=freecom

if test -e $devicelink then device=`/bin/ls -l $devicelink | awk '{print $10}'` idle_state=`cat "/tmp/diskstate_$device"` state=`grep $device /proc/diskstats`

if [ "$state" = "$idle_state" ] then exit 0

else

  echo "-------`date`-------" >> $logfile

  mountpoints=$(/bin/grep $mountdir /etc/mtab | awk '{print $2}')
  if test "$mountpoints"
    then
    echo "disk mounted" >> $logfile
  else
    echo "disk not in use, power down." >> $logfile
    echo "`sg_start --stop $devicelink`" >> $logfile
    idle_state=`grep $device /proc/diskstats`
    echo "$idle_state" > "/tmp/diskstate_$device"
    exit 0
  fi


  for point in $mountpoints
  do
    probe=`fuser -c $point`
    if test "$probe"
      then 
      echo "disk in use" >> $logfile
      exit 0
    fi
  done

  echo "filesystems not in use, power down."        >> $logfile
  echo "`sg_start --stop $devicelink`" >> $logfile
  idle_state=`grep $device /proc/diskstats`
  echo "$idle_state" > "/tmp/diskstate_$device"

fi fi

  1. end
view · edit · print · history · Last edited by obi.
Originally by obi.
Page last modified on January 13, 2007, at 05:00 AM