]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/hddshutdown
remove more bogus logentries.
[ipfire-2.x.git] / src / scripts / hddshutdown
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21 #
22 # IPFire HDD Shutdown state reader
23 #
24
25 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
26 my $diskstats = "";
27 my $newdiskstats = "";
28 my $debug = 1;
29 my $status = "";
30
31 if ($debug){print "### Searching for available Disks ###\n";}
32
33 foreach (@devices){
34 chomp $_;
35 my @array = split(/\//,$_);
36 $diskstats = `cat /var/run/hddstats-$array[$#array] 2>/dev/null`;
37 chomp $diskstats;
38 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
39 chomp $newdiskstats;
40 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
41 chomp $status;
42
43 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
44 if (-e "/var/run/hddshutdown-$array[$#array]" && $status !~/standby/)
45 {
46 if ($debug){print "Remove wrong standby marking\n";}
47 if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
48 }
49
50 if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
51 if ($diskstats eq $newdiskstats && (! -e "/var/run/hddshutdown-$array[$#array]") )
52 {
53 if ($debug){print "Setting Device ".$_." to standby ... ";}
54 $status = `hdparm -y /dev/$_ 2>&1`;
55 chomp $status;
56 if ($status !~/Invalid/)
57 {
58 if ($debug){print "OK\n";}
59 system("touch /var/run/hddshutdown-$array[$#array]");
60 }
61 else
62 {
63 if ($debug){print "FAIL\n";}
64 }
65 }
66 if ($diskstats ne $newdiskstats)
67 {
68 if ($debug){print "Device ".$_." is active.\n";}
69 if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
70 }
71 system("echo $newdiskstats > /var/run/hddstats-$array[$#array]");
72 }
73
74 # end