Page 2 of 2

Posted: Sat Jun 12, 2004 6:25 pm
by feyd

Code: Select all

<?php

preg_match('#md\d\s*?\:\s*?active.*?((hd\w\d\[\d])\s*?)+?\d+?#is', $str, $matches);

?>

Posted: Sat Jun 12, 2004 6:45 pm
by feyd
hward wrote:how do i return the "[UU]" out of

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:

it returns UU or _U or U_
hward, I hope you don't mind me replying here..

Code: Select all

<?php
preg_match('#(\[[^]]+?])\s*?\[[^]]+?]\s*?resync#is',$str,$matches);
?>
you need to do some research into regexes...

Posted: Sat Jun 12, 2004 6:52 pm
by hward
i know I am just not getting it at all i have been on php.net reading and its just flying by me i usually get more from examples i get from you guys but I am not getting this stuff at all

thanks you very much

Posted: Sat Jun 12, 2004 7:00 pm
by hward
all i get from that is the word 'Array'

Posted: Sat Jun 12, 2004 7:23 pm
by feyd
print_r($matches)

Posted: Sat Jun 12, 2004 7:33 pm
by hward
i was using <? echo "$matches"; ?> and getting Array

i get Array ( [0] => [UU] [=========>...........] resync [1] => [UU] ) now

whats the differents between what i was doing and print_r($matches)

Posted: Sat Jun 12, 2004 7:37 pm
by feyd
print_r is able to print the details of objects and arrays, echo is only able to print the simple variables (strings, integers, floats)

Posted: Sat Jun 12, 2004 7:43 pm
by hward
so how do i get it down to just [UU] as what it returns

Posted: Sat Jun 12, 2004 7:53 pm
by feyd
$matches[1]

Posted: Sat Jun 12, 2004 8:00 pm
by hward
is the word resync being in there going to affect it when the drives are in sysnc and the word resync is no longer in the file its reading?

Posted: Sat Jun 12, 2004 8:19 pm
by hward
when the drives are in sync the file reads

Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] unused devices:

I am guessing since the resync is no longer in the file thats why is won't return anything now

Posted: Sat Jun 12, 2004 8:42 pm
by hward
anything wrong with doing it like this

seems to be working but I can't be sure till the drive are in sync again

Code: Select all

<?php
$str = file_get_contents("/proc/mdstat");	  
	 preg_match('#(\[[^]]+?])\s*\[[^]]+?]\s*#is',$str,$matches);
	  $raid = substr($matches[0],5)
?>
<html>
<body>
<? echo "$raid"; ?>
</body>
</html>
?>

Posted: Sun Jun 13, 2004 12:11 am
by feyd

Code: Select all

&#1111;raid1] read_ahead 1024 sectors md0 : active raid1 hde1&#1111;1] hdg1&#1111;0] 39078016 blocks &#1111;2/2] &#1111;UU] unused devices:
if that is returned when it's done syncing... this

Code: Select all

preg_match('#(\[[^]]+?])\s*\[[^]]+?]\s*#is',$str,$matches);
will find "[2/2]".

btw, $raid = substr($matches[0],5) can be simplified to $raid = $matches[1]; for that...