Hi i am looking for somebody who can help me out here, i'm building a script that managed OpenVZ VPS Servers after running a command in shell im given this:
ssh wrote: VEID NPROC STATUS IP_ADDR HOSTNAME
110 55 running 102.95.136.9 server.vpsempire.net
120 54 running 102.95.14.3 server.digitalised-data.com
140 27 running 102.95.153.69 server.avoyellesparishonline.com
150 65 running 19.58.16.1 vps01.ainap.com
170 55 running 162.125.168.158 vps.joyus.org
Formatted exactly as above, i am trying to display the above information in variables, Which is easy if i have only 1 as the spacing is different etc.
for example VEID: 110
i can do $array[4] to display VEID and $array[12] to display HOSTNAME, but on VEID 120: Hostname becomes $array[11] due to the +1 Whitespace from the smaller IP. and this happens between all fields.
I need somebody who can be real real kind and fix this little regex script up for me 🙂 here is my current code:
<?php
$command = "sudo -u root /usr/sbin/vzlist $veid";
$io = array();
$p = proc_open($command,
array(1 => array('pipe', 'w'),
2 => array('pipe', 'w')),
$io);
/* Read output sent to stdout. */
while (!feof($io[1])) {
$output .= htmlspecialchars(fgets($io[1]),
ENT_COMPAT, 'UTF-8');
}
/* Read output sent to stderr. */
while (!feof($io[2])) {
$output .= htmlspecialchars(fgets($io[2]),
ENT_COMPAT, 'UTF-8');
}
fclose($io[1]);
fclose($io[2]);
proc_close($p);
//echo('<pre>'.$output.'</pre>');
$line = explode("HOSTNAME", $output);
//print_r($line);
$spaces = explode(" ", $line[1]);
$no_procs = $spaces[40];
$ve_status = $spaces[41];
$ve_mainip = $spaces[42];
$ve_hname = $spaces[44];
echo "<div align='center'>
<table border='0' cellpadding='5' cellspacing='0' width='100%' bgcolor='#FFFFCC' style='border: 1px solid #FFFF3E; padding: 0'>
<tr>
<td width='25%'><b><font face='Verdana' size='2'>VPS Status:</font></b></td>
<td width='25%'><font face='Verdana' size='2'>$ve_status</font></td>
<td width='25%'><b><font face='Verdana' size='2'>Master IP:</font></b></td>
<td width='25%'><font face='Verdana' size='2'>$ve_mainip</font></td>
</tr>
<tr>
<td width='25%'><b><font face='Verdana' size='2'>Running Processes:</font></b></td>
<td width='25%'><font face='Verdana' size='2'>$no_procs</font></td>
<td width='25%'><b><font face='Verdana' size='2'>Hostname:</font></b></td>
<td width='25%'><font face='Verdana' size='2'>$ve_hname</font></td>
</tr>
</table>
</div>";
?>