]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/hddshutdown
sdparm eingebaut.
[ipfire-2.x.git] / src / scripts / hddshutdown
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 # 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
8 #
9
10 # begin
11
12 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
13 my $diskstats = "";
14 my $newdiskstats = "";
15 my $debug = 1;
16 my $status = "unknown";
17
18 if ($debug){print "### Searching for available Disks ###\n";}
19
20 foreach (@devices){
21 chomp $_;
22 $diskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
23 $status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
24 chomp $status;
25 chomp $diskstats;
26 if ($debug){print "Device ".$_." is in status".$status." and has ".$diskstats." write and read Requests.\n";}
27 sleep 30;
28 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
29 chomp $newdiskstats;
30
31 if ($diskstats eq $newdiskstats && $status !=~/standby/){
32 if ($debug){print "Device ".$_." is set to standy.\n";}
33 system("/sbin/hdparm -y /dev/$_");
34 system("touch /tmp/hddshutdown-$_");
35 }
36 else{
37 if ($debug){print "Device ".$_." is active.\n";}
38 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
39 }
40 }
41
42 # end