]>
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}'`; |
1609fbfd CS |
23 | |
24 | if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;} | |
25 | else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;} | |
26 | ||
56b7a3e2 CS |
27 | chomp $status; |
28 | chomp $diskstats; | |
1609fbfd | 29 | if ($debug){print "Device ".$_." is in status ".$status." and has ".$diskstats." write and read Requests.\n";} |
56b7a3e2 | 30 | sleep 30; |
1609fbfd | 31 | |
56b7a3e2 CS |
32 | $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`; |
33 | chomp $newdiskstats; | |
34 | ||
1609fbfd | 35 | if ($diskstats eq $newdiskstats && $status !~/standby/){ |
56b7a3e2 | 36 | if ($debug){print "Device ".$_." is set to standy.\n";} |
1609fbfd CS |
37 | if ( $_ =~ /^s/ ){system("sdparm --command=stop /dev/$_");} |
38 | else {system("/sbin/hdparm -y /dev/$_");} | |
56b7a3e2 | 39 | system("touch /tmp/hddshutdown-$_"); |
6c666a3b | 40 | } |
1609fbfd | 41 | elsif ($diskstatus{$_} ne "0" ){ |
51585c70 CS |
42 | if ($debug){print "Device ".$_." is active.\n";} |
43 | if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); } | |
6c666a3b | 44 | } |
1609fbfd CS |
45 | elsif ( $status =~/standby/ ){ |
46 | if ($debug){print "Device ".$_." is in standby mode.\n";} | |
47 | } | |
6c666a3b | 48 | } |
3bc32eab | 49 | |
6c666a3b | 50 | # end |