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:51 am
Hi I can read my file ok with this code
Code: Select all
<?php
if (!($fp = fopen("/proc/mdstat", "r")))
exit("Unable to open the input file.");
while (!feof($fp))
{
$c = fgetc($fp);
print $c;
}
fclose($fp);
?>
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:
All I want out of it is
resync = 34.9%
finish=41.0min
Can I pull out just that part of the file?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Jun 11, 2004 11:07 am
Code: Select all
$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";
something like that.
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Fri Jun 11, 2004 11:32 am
that works fine but when it is finished it shows
resync=% finish= min
how can you make it show
resync=100% finish=complete
when it is finished and theres nothing to show
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Jun 11, 2004 11:38 am
it means you need to tweak the regexp I gave to you to match your sting.
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Fri Jun 11, 2004 12:18 pm
I guess I don't understand what you mean
you mean like if else stuff?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Jun 11, 2004 3:51 pm
does it work while the process you monitor still running? something like
resync = 34.9%
finish=41.0min
?
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Fri Jun 11, 2004 4:04 pm
I got it working with and if else
thanks