S
speedster
Hi.
I need some help converting some php to perl.
$meminfo = shell_exec( "free -o" );
I need to execute "free-o" in shell and get the results.
It grabs memory information about a linux webserver.
If it is also possible to run a regular expression on this data that
would also be great.
It then outputs it in a nice format.
Here it is:
preg_match_all("/Mem:\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+).*?Swap:\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)/si",$meminfo,$mtype);
array_shift($mtype);
echo("<mem>"."\n");
echo("<total>".$mtype[0][0]."</total>"."\n");
echo("<used>".$mtype[1][0]."</used>"."\n");
echo("<free>".$mtype[2][0]."</free>"."\n");
echo("<shared>".$mtype[3][0]."</shared>"."\n");
echo("<buffers>".$mtype[4][0]."</buffers>"."\n");
echo("<cached>".$mtype[5][0]."</cached>"."\n");
echo("</mem>"."\n");
echo("<swap>"."\n");
echo("<total>".$mtype[6][0]."</total>"."\n");
echo("<used>".$mtype[7][0]."</used>"."\n");
echo("<free>".$mtype[8][0]."</free>"."\n");
echo("</swap>"."\n");
echo("</meminfo>"."\n");
If you can do either bit please give me an example of what I would
write.
(perl shell exec or perl regular expression)
This is the first line of my cgi script. Im not sure if I have to
declare headers or anything. Im new to perl.
This script outputs xml and as php is being turned off on my server I
must convert it to perl.
Thanks alot in advance.
William
I need some help converting some php to perl.
$meminfo = shell_exec( "free -o" );
I need to execute "free-o" in shell and get the results.
It grabs memory information about a linux webserver.
If it is also possible to run a regular expression on this data that
would also be great.
It then outputs it in a nice format.
Here it is:
preg_match_all("/Mem:\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+).*?Swap:\s+?([0-9]+)\s+?([0-9]+)\s+?([0-9]+)/si",$meminfo,$mtype);
array_shift($mtype);
echo("<mem>"."\n");
echo("<total>".$mtype[0][0]."</total>"."\n");
echo("<used>".$mtype[1][0]."</used>"."\n");
echo("<free>".$mtype[2][0]."</free>"."\n");
echo("<shared>".$mtype[3][0]."</shared>"."\n");
echo("<buffers>".$mtype[4][0]."</buffers>"."\n");
echo("<cached>".$mtype[5][0]."</cached>"."\n");
echo("</mem>"."\n");
echo("<swap>"."\n");
echo("<total>".$mtype[6][0]."</total>"."\n");
echo("<used>".$mtype[7][0]."</used>"."\n");
echo("<free>".$mtype[8][0]."</free>"."\n");
echo("</swap>"."\n");
echo("</meminfo>"."\n");
If you can do either bit please give me an example of what I would
write.
(perl shell exec or perl regular expression)
This is the first line of my cgi script. Im not sure if I have to
declare headers or anything. Im new to perl.
This script outputs xml and as php is being turned off on my server I
must convert it to perl.
Thanks alot in advance.
William