]>
Commit | Line | Data |
---|---|---|
6c666a3b MT |
1 | #!/usr/bin/perl |
2 | # | |
51585c70 | 3 | # IPFire HDD Shutdown state reader |
6c666a3b MT |
4 | # |
5 | # This code is distributed under the terms of the GPL | |
6 | # | |
51585c70 | 7 | # 20.08.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org |
6c666a3b MT |
8 | # |
9 | ||
10 | # begin | |
11 | ||
51585c70 CS |
12 | my @proc = `cat /proc/diskstats`; |
13 | my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; | |
14 | my %diskstatus = ""; | |
3bc32eab | 15 | my %diskstate = ""; |
51585c70 CS |
16 | my $debug = 1; |
17 | my $status = "unknown"; | |
6c666a3b | 18 | |
51585c70 | 19 | if ($debug){print "### Reading Diskstats ###\n";} |
6c666a3b | 20 | |
51585c70 CS |
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 | } | |
6c666a3b | 26 | |
51585c70 | 27 | if ($debug){print "### Searching for available Disks ###\n";} |
6c666a3b | 28 | |
51585c70 CS |
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`; | |
6c666a3b | 33 | |
51585c70 CS |
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-$_"); | |
6c666a3b | 38 | } |
51585c70 CS |
39 | elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){ |
40 | if ($debug){print "Device ".$_." is active.\n";} | |
41 | if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); } | |
6c666a3b | 42 | } |
6c666a3b | 43 | } |
3bc32eab | 44 | |
6c666a3b | 45 | # end |