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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 6:25 pm
Code: Select all
<?php
preg_match('#md\d\s*?\:\s*?active.*?((hd\w\d\[\d])\s*?)+?\d+?#is', $str, $matches);
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 6:45 pm
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...
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 6:52 pm
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
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 7:00 pm
all i get from that is the word 'Array'
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 7:23 pm
print_r($matches)
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 7:33 pm
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)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 7:37 pm
print_r is able to print the details of objects and arrays, echo is only able to print the simple variables (strings, integers, floats)
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 7:43 pm
so how do i get it down to just [UU] as what it returns
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jun 12, 2004 7:53 pm
$matches[1]
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 8:00 pm
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?
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 8:19 pm
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
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Sat Jun 12, 2004 8:42 pm
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>
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jun 13, 2004 12:11 am
Code: Select all
їraid1] read_ahead 1024 sectors md0 : active raid1 hde1ї1] hdg1ї0] 39078016 blocks ї2/2] ї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...