]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/hddshutdown
Remove output of "ipsecctrl R".
[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#
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 21 chomp $_;
5384809b 22 my @array = split(/\//,$_);
965f4547 23 $diskstats = `cat /var/run/hddstats-$array[$#array]`;
471a46f7
CS
24 chomp $diskstats;
25 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
26 chomp $newdiskstats;
27 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
28 chomp $status;
29
30 if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
965f4547 31 if (-e "/var/run/hddshutdown-$array[$#array]" && $status !~/standby/)
471a46f7
CS
32 {
33 if ($debug){print "Remove wrong standby marking\n";}
965f4547 34 if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
471a46f7
CS
35 }
36
37 if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
965f4547 38 if ($diskstats eq $newdiskstats && (! -e "/var/run/hddshutdown-$array[$#array]") )
471a46f7
CS
39 {
40 if ($debug){print "Setting Device ".$_." to standby ... ";}
41 $status = `hdparm -y /dev/$_ 2>&1`;
42 chomp $status;
5384809b 43 if ($status !~/Invalid/)
471a46f7
CS
44 {
45 if ($debug){print "OK\n";}
965f4547 46 system("touch /var/run/hddshutdown-$array[$#array]");
471a46f7
CS
47 }
48 else
49 {
5384809b 50 if ($debug){print "FAIL\n";}
471a46f7
CS
51 }
52 }
53 if ($diskstats ne $newdiskstats)
54 {
55 if ($debug){print "Device ".$_." is active.\n";}
965f4547 56 if ( -e "/var/run/hddshutdown-$array[$#array]" ) { system("unlink /var/run/hddshutdown-$array[$#array]"); }
471a46f7 57 }
965f4547 58 system("echo $newdiskstats > /var/run/hddstats-$array[$#array]");
6c666a3b 59}
3bc32eab 60
6c666a3b 61# end