]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - src/scripts/hddshutdown
Hddstatus auf der Media CGI nochmal ueberarbeitet
[people/pmueller/ipfire-2.x.git] / src / scripts / hddshutdown
... / ...
CommitLineData
1#!/usr/bin/perl
2#
3# IPFire HDD Shutdown state reader
4#
5# This code is distributed under the terms of the GPL
6#
7# 20.08.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
8#
9
10# begin
11
12my @proc = `cat /proc/diskstats`;
13my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
14my %diskstatus = "";
15my %diskstate = "";
16my $debug = 1;
17my $status = "unknown";
18
19if ($debug){print "### Reading Diskstats ###\n";}
20
21foreach (@proc){
22my @line = split(/ +/,$_);
23$diskstatus{$line[3]} =$line[12];
24if ($debug){print "Getting device ".$line[3]." with the following value ".$line[12]."\n";}
25}
26
27if ($debug){print "### Searching for available Disks ###\n";}
28
29foreach (@devices){
30chomp $_;
31if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";}
32$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
33
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-$_");
38 }
39 elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
40 if ($debug){print "Device ".$_." is active.\n";}
41 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
42 }
43}
44
45# end