Files
bpfire/src/scripts/hddshutdown
ms a45de06ef1 Hddshutdown-Fixes.
git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@792 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
2007-08-20 21:05:15 +00:00

58 lines
1.5 KiB
Perl

#!/usr/bin/perl
#
# IPFire HDD Shutdown state reader
#
# This code is distributed under the terms of the GPL
#
# 20.08.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
#
# begin
my @proc = `cat /proc/diskstats`;
my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
my %diskstatus = "";
my $debug = 1;
my $status = "unknown";
if ( @ARGV[0] eq "state" ){
my $hdd = @ARGV[1];
$status = `hdparm -C /dev/$hdd | tail -1 | cut -d: -f2`;
if ( $status=~/standby/){
my $ftime = localtime((stat("/tmp/hddshutdown-$hdd"))[9]);
print"<B>Disk $hdd status: <font color=#00FF00>standby</font></B> (since $ftime)";
}
else{
print"<B>Disk $hdd status: <font color=#FF0000>active</font></B>";
}
exit;
}
if ($debug){print "### Reading Diskstats ###\n";}
foreach (@proc){
my @line = split(/ +/,$_);
$diskstatus{$line[3]} =$line[12];
if ($debug){print "Getting device ".$line[3]." with the following value ".$line[12]."\n";}
}
if ($debug){print "### Searching for available Disks ###\n";}
foreach (@devices){
chomp $_;
if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";}
$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
if ($diskstatus{$_} eq "0" && $status !=~/standby/){
if ($debug){print "Device ".$_." is set to standy.\n";}
system("/sbin/hdparm -y /dev/$_");
system("touch /tmp/hddshutdown-$_");
}
elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
if ($debug){print "Device ".$_." is active.\n";}
if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
}
}
# end