]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/hddshutdown-state
makegraphs umgebaut, sodass nurnoch rrd daten geschrieben werden die graphen
[people/pmueller/ipfire-2.x.git] / src / scripts / hddshutdown-state
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 # 11.05.2006 Arne Fitzenreiter
8 #
9
10 # begin
11
12 my $hdd = @ARGV[0];
13 my $hdddev = "/dev/$hdd";
14
15 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
16 $atime, $mtime, $ctime, $blksize, $blocks) = stat($hdddev);
17
18 my $major = $rdev >> 8;
19 my $minor = ($rdev & 0xFF) >> 6;
20
21 open STAT, "/proc/stat";
22 my @diskstat = <STAT>;
23 close (STAT);
24 foreach my $line (@diskstat)
25 {
26 chomp ($line);
27 my @temp = split(/\:\ /,$line);
28 if ($temp[1]) {
29 my @devicestat = split(/\ /,$temp[1]);
30 foreach my $stats (@devicestat)
31 {
32 chomp ($stats);
33 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
34 if ($major eq $fields[1] and $minor eq $fields[2])
35 {
36 $readwritereq = $fields[3];
37 }
38 }
39 }
40 }
41
42 if (! -e "/tmp/hddshutdown-$hdd" ) {
43 print"<B>Disk $hdddev status:</B> unknown"
44
45 }
46
47 if ( -e "/tmp/hddshutdown-$hdd" ) {
48 open STAT,"/tmp/hddshutdown-$hdd";
49 my $lastsleepstate = <STAT>;
50 close (STAT);
51 my $ftime = localtime((stat("/tmp/hddshutdown-$hdd"))[9]);
52 if (! ($lastsleepstate==$readwritereq)) {
53 print"<B>Disk $hdddev status: <font color=#FF0000>active</font></B>";
54 }
55 if ( ($lastsleepstate==$readwritereq)) {
56 print"<B>Disk $hdddev status: <font color=#00FF00>standby</font></B> (since $ftime)";
57 }
58
59 }
60
61
62
63 # end