]>
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 = ""; | |
15 | my $debug = 1; | |
16 | my $status = "unknown"; | |
6c666a3b | 17 | |
51585c70 CS |
18 | if ( @ARGV[0] eq "state" ){ |
19 | my $hdd = @ARGV[1]; | |
20 | $status = `hdparm -C /dev/$hdd | tail -1 | cut -d: -f2`; | |
6c666a3b | 21 | |
51585c70 CS |
22 | if ( $status=~/standby/){ |
23 | my $ftime = localtime((stat("/tmp/hddshutdown-$hdd"))[9]); | |
24 | print"<B>Disk $hdddev status: <font color=#00FF00>standby</font></B> (since $ftime)"; | |
25 | } | |
26 | else{ | |
27 | print"<B>Disk $hdddev status: <font color=#FF0000>active</font></B>"; | |
28 | } | |
29 | exit; | |
30 | } | |
6c666a3b | 31 | |
51585c70 | 32 | if ($debug){print "### Reading Diskstats ###\n";} |
6c666a3b | 33 | |
51585c70 CS |
34 | foreach (@proc){ |
35 | my @line = split(/ +/,$_); | |
36 | $diskstatus{$line[3]} =$line[12]; | |
37 | if ($debug){print "Getting device ".$line[3]." with the following value ".$line[12]."\n";} | |
38 | } | |
6c666a3b | 39 | |
51585c70 | 40 | if ($debug){print "### Searching for available Disks ###\n";} |
6c666a3b | 41 | |
51585c70 CS |
42 | foreach (@devices){ |
43 | chomp $_; | |
44 | if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";} | |
45 | $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`; | |
6c666a3b | 46 | |
51585c70 CS |
47 | if ($diskstatus{$_} eq "0" && $status !=~/standby/){ |
48 | if ($debug){print "Device ".$_." is set to standy.\n";} | |
49 | system("/sbin/hdparm -y /dev/$_"); | |
50 | system("touch /tmp/hddshutdown-$_"); | |
6c666a3b | 51 | } |
51585c70 CS |
52 | elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){ |
53 | if ($debug){print "Device ".$_." is active.\n";} | |
54 | if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); } | |
6c666a3b | 55 | } |
6c666a3b | 56 | } |
6c666a3b | 57 | # end |