small problem i think

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

small problem i think

Post by hward »

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 »

About 0? What do you mean about 0? 0 would be

Code: Select all

if( $matches[1] == '0' )
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

the if statement isn't the problem

Code: Select all

<?php
  $str = file_get_contents("/proc/mdstat", "r"); 
preg_match("/.*active raid1.*resync = (&#1111;0-9.]*)%.*finish=(&#1111;0-9.]*)min/m", $str, $matches); 
echo "resync = $matches&#1111;1]%\nfinish=$matches&#1111;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 »

Code: Select all

<?php

$str = file_get_contents("/proc/mdstat"); 
preg_match("/.*resync = (&#1111;0-9.]*)%.*finish=(&#1111;0-9.]*)min/m", $str, $matches); 
echo "resync = $matches&#1111;1]%\nfinish=$matches&#1111;2]min\n"; 


?>
I ment to send this one
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

no i haven't i not sure how to change it to a float
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$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 »

still nothing
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

prints Array ( )
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

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 »

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>


?>

?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

get in the habbit of using EDIT function
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

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:
Post Reply