]>
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 | # | |
56b7a3e2 | 7 | # 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org |
471a46f7 | 8 | # 22.09.2007 Arne_F - fitzenreiter.de - arne@fitzenreiter.de |
6c666a3b MT |
9 | |
10 | # begin | |
11 | ||
51585c70 | 12 | my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; |
56b7a3e2 CS |
13 | my $diskstats = ""; |
14 | my $newdiskstats = ""; | |
51585c70 | 15 | my $debug = 1; |
471a46f7 | 16 | my $status = ""; |
6c666a3b | 17 | |
51585c70 | 18 | if ($debug){print "### Searching for available Disks ###\n";} |
6c666a3b | 19 | |
51585c70 | 20 | foreach (@devices){ |
471a46f7 | 21 | chomp $_; |
5384809b CS |
22 | my @array = split(/\//,$_); |
23 | $diskstats = `cat /tmp/hddstats-$array[$#array]`; | |
471a46f7 CS |
24 | chomp $diskstats; |
25 | $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`; | |
26 | chomp $newdiskstats; | |
27 | $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`; | |
28 | chomp $status; | |
29 | ||
30 | if ($debug){print "Device ".$_." IDE Power status:".$status."\n";} | |
5384809b | 31 | if (-e "/tmp/hddshutdown-$array[$#array]" && $status !~/standby/) |
471a46f7 CS |
32 | { |
33 | if ($debug){print "Remove wrong standby marking\n";} | |
5384809b | 34 | if ( -e "/tmp/hddshutdown-$array[$#array]" ) { system("unlink /tmp/hddshutdown-$array[$#array]"); } |
471a46f7 CS |
35 | } |
36 | ||
37 | if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";} | |
5384809b | 38 | if ($diskstats eq $newdiskstats && (! -e "/tmp/hddshutdown-$array[$#array]") ) |
471a46f7 CS |
39 | { |
40 | if ($debug){print "Setting Device ".$_." to standby ... ";} | |
41 | $status = `hdparm -y /dev/$_ 2>&1`; | |
42 | chomp $status; | |
5384809b | 43 | if ($status !~/Invalid/) |
471a46f7 CS |
44 | { |
45 | if ($debug){print "OK\n";} | |
5384809b | 46 | system("touch /tmp/hddshutdown-$array[$#array]"); |
471a46f7 CS |
47 | } |
48 | else | |
49 | { | |
5384809b | 50 | if ($debug){print "FAIL\n";} |
471a46f7 CS |
51 | } |
52 | } | |
53 | if ($diskstats ne $newdiskstats) | |
54 | { | |
55 | if ($debug){print "Device ".$_." is active.\n";} | |
5384809b | 56 | if ( -e "/tmp/hddshutdown-$array[$#array]" ) { system("unlink /tmp/hddshutdown-$array[$#array]"); } |
471a46f7 | 57 | } |
5384809b | 58 | system("echo $newdiskstats > /tmp/hddstats-$array[$#array]"); |
6c666a3b | 59 | } |
3bc32eab | 60 | |
6c666a3b | 61 | # end |