]>
git.ipfire.org Git - people/teissler/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 $diskstats = `cat /tmp/hddstats-$_`;
24 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
26 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
29 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
30 if (-e
"/tmp/hddshutdown-$_" && $status !~/standby/)
32 if ($debug){print "Remove wrong standby marking\n";}
33 if ( -e
"/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
36 if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
37 if ($diskstats eq $newdiskstats && (! -e
"/tmp/hddshutdown-$_") )
39 if ($debug){print "Setting Device ".$_." to standby ... ";}
40 $status = `hdparm -y /dev/$_ 2>&1`;
42 if ($status !~/failed/)
44 if ($debug){print "OK\n";}
45 system("touch /tmp/hddshutdown-$_");
49 if ($debug){print "FAIL\n";}
52 if ($diskstats ne $newdiskstats)
54 if ($debug){print "Device ".$_." is active.\n";}
55 if ( -e
"/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
57 system("echo $newdiskstats > /tmp/hddstats-$_");