]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/hddshutdown
Neuer Versuch fuer Syslog
[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
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}'`;
51585c70 23$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
56b7a3e2
CS
24chomp $status;
25chomp $diskstats;
26if ($debug){print "Device ".$_." is in status".$status." and has ".$diskstats." write and read Requests.\n";}
27sleep 30;
28$newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
29chomp $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-$_");
6c666a3b 35 }
51585c70
CS
36 elsif ($diskstatus{$_} ne "0" || $status !=~/standby/){
37 if ($debug){print "Device ".$_." is active.\n";}
38 if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
6c666a3b 39 }
6c666a3b 40}
3bc32eab 41
6c666a3b 42# end