Mega Code Archive

 
Categories / Php / Development
 

Using popen() to Read the Output of the UNIX who Command

<html> <head> <title>Using popen() to read the output of the UNIX who command</title> </head> <body> <h2>Administrators currently logged on to the server</h1> <?php $ph = popen( "who", "r" ) or die( "Couldn't open connection to 'who' command" ); $host="www.rntsoft.com"; while ( ! feof( $ph )  ){     $line = fgets( $ph, 1024 );     if ( strlen( $line ) <= 1 )         continue;     $line = ereg_replace("^([a-zA-Z0-9_\-]+).*", "<a href=\"mailto:\\1@$host\">\\1</a><BR>\n",$line );     print "$line"; } pclose( $ph ); ?> </table> </body> </html>