]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/hddshutdown
Hddstatus auf der Media CGI nochmal ueberarbeitet
[people/pmueller/ipfire-2.x.git] / src / scripts / hddshutdown
CommitLineData
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
12my @proc = `cat /proc/diskstats`;
13my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
14my %diskstatus = "";
3bc32eab 15my %diskstate = "";
51585c70
CS
16my $debug = 1;
17my $status = "unknown";
6c666a3b 18
51585c70 19if ($debug){print "### Reading Diskstats ###\n";}
6c666a3b 20
51585c70
CS
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}
6c666a3b 26
51585c70 27if ($debug){print "### Searching for available Disks ###\n";}
6c666a3b 28
51585c70
CS
29foreach (@devices){
30chomp $_;
31if ($debug){print "Device ".$_." has ".$diskstatus{$_}." IO Requests.\n";}
32$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
6c666a3b 33
51585c70
CS
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-$_");
6c666a3b 38 }
51585c70
CS
39 elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
40 if ($debug){print "Device ".$_." is active.\n";}
41 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
6c666a3b 42 }
6c666a3b 43}
3bc32eab 44
6c666a3b 45# end