]>
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 |
6c666a3b MT |
8 | # |
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 CS |
15 | my $debug = 1; |
16 | my $status = "unknown"; | |
6c666a3b | 17 | |
51585c70 | 18 | if ($debug){print "### Searching for available Disks ###\n";} |
6c666a3b | 19 | |
51585c70 CS |
20 | foreach (@devices){ |
21 | chomp $_; | |
56b7a3e2 | 22 | $diskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`; |
51585c70 | 23 | $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`; |
56b7a3e2 CS |
24 | chomp $status; |
25 | chomp $diskstats; | |
26 | if ($debug){print "Device ".$_." is in status".$status." and has ".$diskstats." write and read Requests.\n";} | |
27 | sleep 30; | |
28 | $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`; | |
29 | chomp $newdiskstats; | |
30 | ||
31 | if ($diskstats eq $newdiskstats && $status !=~/standby/){ | |
32 | if ($debug){print "Device ".$_." is set to standy.\n";} | |
33 | system("/sbin/hdparm -y /dev/$_"); | |
34 | system("touch /tmp/hddshutdown-$_"); | |
6c666a3b | 35 | } |
51585c70 CS |
36 | elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){ |
37 | if ($debug){print "Device ".$_." is active.\n";} | |
38 | if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); } | |
6c666a3b | 39 | } |
6c666a3b | 40 | } |
3bc32eab | 41 | |
6c666a3b | 42 | # end |