]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/hddshutdown
Die hddtemp.db ins SVN gepackt und aktualisiert.
[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
6c666a3b
MT
8#
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
CS
15my $debug = 1;
16my $status = "unknown";
6c666a3b 17
51585c70 18if ($debug){print "### Searching for available Disks ###\n";}
6c666a3b 19
51585c70
CS
20foreach (@devices){
21chomp $_;
56b7a3e2 22$diskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
1609fbfd
CS
23
24if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;}
25else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;}
26
56b7a3e2
CS
27chomp $status;
28chomp $diskstats;
1609fbfd 29if ($debug){print "Device ".$_." is in status ".$status." and has ".$diskstats." write and read Requests.\n";}
56b7a3e2 30sleep 30;
1609fbfd 31
56b7a3e2
CS
32$newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
33chomp $newdiskstats;
34
1609fbfd 35 if ($diskstats eq $newdiskstats && $status !~/standby/){
56b7a3e2 36 if ($debug){print "Device ".$_." is set to standy.\n";}
1609fbfd
CS
37 if ( $_ =~ /^s/ ){system("sdparm --command=stop /dev/$_");}
38 else {system("/sbin/hdparm -y /dev/$_");}
56b7a3e2 39 system("touch /tmp/hddshutdown-$_");
6c666a3b 40 }
1609fbfd 41 elsif ($diskstatus{$_} ne "0" ){
51585c70
CS
42 if ($debug){print "Device ".$_." is active.\n";}
43 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
6c666a3b 44 }
1609fbfd
CS
45 elsif ( $status =~/standby/ ){
46 if ($debug){print "Device ".$_." is in standby mode.\n";}
47 }
6c666a3b 48}
3bc32eab 49
6c666a3b 50# end