]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/hddshutdown
hddshutdown mit sonderbehandlung für SATA
[people/teissler/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
24 if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;}
25 else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;}
26
27 chomp $status;
28 chomp $diskstats;
29 if ($debug){print "Device ".$_." is in status ".$status." and has ".$diskstats." write and read Requests.\n";}
30 sleep 30;
31
32 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
33 chomp $newdiskstats;
34
35 if ($diskstats eq $newdiskstats && $status !~/standby/){
36 if ($debug){print "Device ".$_." is set to standy.\n";}
37 if ( $_ =~ /^s/ ){system("sdparm --command=stop /dev/$_");}
38 else {system("/sbin/hdparm -y /dev/$_");}
39 system("touch /tmp/hddshutdown-$_");
40 }
41 elsif ($diskstatus{$_} ne "0" ){
42 if ($debug){print "Device ".$_." is active.\n";}
43 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
44 }
45 elsif ( $status =~/standby/ ){
46 if ($debug){print "Device ".$_." is in standby mode.\n";}
47 }
48 }
49
50 # end