]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/hddshutdown
853f769e4bffe5961e458224c45169699f4416ed
3 # IPFire HDD Shutdown state reader
5 # This code is distributed under the terms of the GPL
7 # 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
12 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
14 my $newdiskstats = "";
16 my $status = "unknown";
18 if ($debug){print "### Searching for available Disks ###\n";}
22 $diskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
24 if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;}
25 else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;}
29 if ($debug){print "Device ".$_." is in status ".$status." and has ".$diskstats." write and read Requests.\n";}
32 $newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
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-$_");
41 elsif ($diskstatus{$_} ne "0" ){
42 if ($debug){print "Device ".$_." is active.\n";}
43 if ( -e
"/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
45 elsif ( $status =~/standby/ ){
46 if ($debug){print "Device ".$_." is in standby mode.\n";}