]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/hddshutdown
Meine Platte zur hddtemp.db hinzugefuegt
[people/teissler/ipfire-2.x.git] / src / scripts / hddshutdown
1 #!/usr/bin/perl
2 #
3 # IPFire HDD Shutdown state reader
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
8 # 22.09.2007 Arne_F - fitzenreiter.de - arne@fitzenreiter.de
9
10 # begin
11
12 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
13 my $diskstats = "";
14 my $newdiskstats = "";
15 my $debug = 1;
16 my $status = "";
17
18 if ($debug){print "### Searching for available Disks ###\n";}
19
20 foreach (@devices){
21 chomp $_;
22 $diskstats = `cat /tmp/hddstats-$_`;
23 chomp $diskstats;
24 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
25 chomp $newdiskstats;
26 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
27 chomp $status;
28
29 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
30 if (-e "/tmp/hddshutdown-$_" && $status !~/standby/)
31 {
32 if ($debug){print "Remove wrong standby marking\n";}
33 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
34 }
35
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-$_") )
38 {
39 if ($debug){print "Setting Device ".$_." to standby ... ";}
40 $status = `hdparm -y /dev/$_ 2>&1`;
41 chomp $status;
42 if ($status !~/failed/)
43 {
44 if ($debug){print "OK\n";}
45 system("touch /tmp/hddshutdown-$_");
46 }
47 else
48 {
49 if ($debug){print "FAIL\n";}
50 }
51 }
52 if ($diskstats ne $newdiskstats)
53 {
54 if ($debug){print "Device ".$_." is active.\n";}
55 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
56 }
57 system("echo $newdiskstats > /tmp/hddstats-$_");
58 }
59
60 # end