phil can you teach me.

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
User avatar
fernando
Posts: 240
Joined: Thu Jul 10, 2003 6:00 pm

phil can you teach me.

Post by fernando »

hi phil

i was looking at your function code.
and i found

Code: Select all

function getDiskPercent()
{
	$df = shell_exec( 'df '.ZM_DIR_EVENTS );
	$space = -1;
	if ( preg_match( '/\s(\d+)%/ms', $df, $matches ) )
		$space = $matches[1];
	return( $space );
}

function getDiskBlocks()
{
	$df = shell_exec( 'df '.ZM_DIR_EVENTS );
	$space = -1;
	if ( preg_match( '/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches ) )
		$space = $matches[1];
	return( $space );
}
i dont get the preg_match thing.. i look at the internet but just the basic description.
i cant figureit out what '/\s(\d+)\s+\d+\s+\d+%/ms' mean .. and how this can tell you the disk blocks using the "df" funcion.
can you tell me a good resouce to read..
Fernando
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

These are perl regular expressions. It's a pretty standard format and typing 'perdoc perlre' on most Linux systems will get you the hard facts. However it's not a very friendly introduction. I'm sure you'll get something helpful (probably in Spanish) if you google for "regular expression tutorial" or something like that. If you're really stuck let me know and I'll see what I can find.

Essentially in the examples you gave though, \s is whitespace (space or tab) and \d is a numerical digit (0-9). Anything in parenthesis () will be captured and returned in the $matches array and a + just means there must be one or more of the preceding items, so \d+ means at least one digit, so 1 or 45 or 0974943 etc. The /ms bit at the end relates to how the expresion matches over multiple lines.

Phil
User avatar
fernando
Posts: 240
Joined: Thu Jul 10, 2003 6:00 pm

Post by fernando »

thanks phil
i get it a little more.
i found some more info like http://www.amk.ca/python/howto/regex/

but .. how you get the diskblock from df?
from this function i get 3199748
but how this number came from

Code: Select all

[root@localhost root]# df /var/www/html
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda6             108G  3,1G  100G   3% /var
Fernando
User avatar
fernando
Posts: 240
Joined: Thu Jul 10, 2003 6:00 pm

Post by fernando »

ok here a good tutorial
http://weblogtoolscollection.com/regex/regex.php

lots of examples.

then you can dowload editpad to practice. :)

thanks again phil
Fernando
Post Reply