]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/hddshutdown
3 # IPFire HDD Shutdown state reader
5 # This code is distributed under the terms of the GPL
7 # 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
8 # 22.09.2007 Arne_F - fitzenreiter.de - arne@fitzenreiter.de
12 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
14 my $newdiskstats = "";
18 if ($debug){print "### Searching for available Disks ###\n";}
22 my @array = split(/\//,$_);
23 $diskstats = `cat /var/run/hddstats-$array[$#array]`;
25 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
27 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
30 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
31 if (-e
"/var/run/hddshutdown-$array[$#array]" && $status !~/standby
/)
33 if ($debug){print "Remove wrong standby marking\n";}
34 if ( -e
"/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
37 if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
38 if ($diskstats eq $newdiskstats && (! -e
"/var/run/hddshutdown-$array[$#array]") )
40 if ($debug){print "Setting Device ".$_." to standby ... ";}
41 $status = `hdparm -y /dev/$_ 2>&1`;
43 if ($status !~/Invalid/)
45 if ($debug){print "OK\n";}
46 system("touch /var/run/hddshutdown-$array[$#array]");
50 if ($debug){print "FAIL\n";}
53 if ($diskstats ne $newdiskstats)
55 if ($debug){print "Device ".$_." is active.\n";}
56 if ( -e
"/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
58 system("echo $newdiskstats > /var/run/hddstats-$array[$#array]");