]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/hddshutdown
Hddstatus auf der Media CGI nochmal ueberarbeitet
[people/pmueller/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 # 20.08.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
8 #
9
10 # begin
11
12 my @proc = `cat /proc/diskstats`;
13 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
14 my %diskstatus = "";
15 my %diskstate = "";
16 my $debug = 1;
17 my $status = "unknown";
18
19 if ($debug){print "### Reading Diskstats ###\n";}
20
21 foreach (@proc){
22 my @line = split(/ +/,$_);
23 $diskstatus{$line[3]} =$line[12];
24 if ($debug){print "Getting device ".$line[3]." with the following value ".$line[12]."\n";}
25 }
26
27 if ($debug){print "### Searching for available Disks ###\n";}
28
29 foreach (@devices){
30 chomp $_;
31 if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";}
32 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
33
34 if ($diskstatus{$_} eq "0" && $status !=~/standby/){
35 if ($debug){print "Device ".$_." is set to standy.\n";}
36 system("/sbin/hdparm -y /dev/$_");
37 system("touch /tmp/hddshutdown-$_");
38 }
39 elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
40 if ($debug){print "Device ".$_." is active.\n";}
41 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
42 }
43 }
44
45 # end