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