PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Fri Jun 11, 2004 10:20 pm
Code: Select all
$str = file_get_contents("/proc/mdstat");
preg_match("/.*resync = ([0-9.]*)%.*finish=([0-9.]*)min/m", $str, $matches);
//$str = file_get_contents("/proc/mdstat");
//preg_match("/.*resync = ([0-9.]*)%.*finish=([0-9.]*)min/m", $str, $matches);
//echo "resync = $matches[1]%\nfinish=$matches[2]min\n";
if( $matches[1] > '0' )
{
need my if statement to go when the resync value is about 0 but it is not going until it is at 10
what am i missing here
everything works fine once it gets past 10
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Sat Jun 12, 2004 8:30 am
About 0? What do you mean about 0? 0 would be
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 9:44 am
the if statement isn't the problem
Code: Select all
<?php
$str = file_get_contents("/proc/mdstat", "r");
preg_match("/.*active raid1.*resync = (ї0-9.]*)%.*finish=(ї0-9.]*)min/m", $str, $matches);
echo "resync = $matchesї1]%\nfinish=$matchesї2]min\n";
?>
Even this only starts to return after the resync is above 10%
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 9:56 am
Code: Select all
<?php
$str = file_get_contents("/proc/mdstat");
preg_match("/.*resync = (ї0-9.]*)%.*finish=(ї0-9.]*)min/m", $str, $matches);
echo "resync = $matchesї1]%\nfinish=$matchesї2]min\n";
?>
I ment to send this one
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 10:37 am
have you tried changing it to a float before checking against it?
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 11:48 am
no i haven't i not sure how to change it to a float
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 1:11 pm
$matches[1] = (float)$matches[1];
$matches[2] = (float)$matches[2];
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 1:16 pm
still nothing
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 1:18 pm
this is what its reading before resync gets up to 10.0%
Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] [>....................] resync = 2.4% (942896/39078016) finish=61.4min speed=10333K/sec unused devices:
after 10%
Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] [======>..............] resync = 34.9% (13670876/39078016) finish=41.0min speed=10324K/sec unused devices:
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 1:41 pm
try (untested)
Code: Select all
preg_match('#resync\s*?=\s*?([\d.]+?)%.*?finish\s*?=\s*?([\d.]+?)\s*?min#is', $str, $matches);
print_r($matches);
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 2:00 pm
prints Array ( )
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 2:07 pm
actually it prints
Array ( [0] => resync = 8.6% (3395120/39078016) finish=59.4min [1] => 8.6 [2] => 59.4 )
i forgot to ad
$str = file_get_contents("/proc/mdstat");
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 2:14 pm
think it works now
Code: Select all
<?php
$str = file_get_contents("/proc/mdstat");
preg_match('#resync\s*?=\s*?([\d.]+?)%.*?finish\s*?=\s*?([\d.]+?)\s*?min#is', $str, $matches);
?>
<html><body>
<? echo "$matches[1]"; ?><br>
<? echo "$matches[2]"; ?>
</body></html>
?>
?>
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 3:09 pm
man i am just not grasping all of this
Code: Select all
<?php
preg_match('#resync\s*?=\s*?([\d.]+?)%.*?finish\s*?=\s*?([\d.]+?)\s*?min#is', $str, $matches);
?>
How can I pull out the : active raid1 hde1[1] hdg1[0] out and have the
$matches[1] = hde1[1]
$matches[2] = hde1[0]
Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] [======>..............] resync = 34.9% (13670876/39078016) finish=41.0min speed=10324K/sec unused devices: