Using popen() to Read the Output of the UNIX who Command : System Command « Development « PHP






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.java2s.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>

           
       








Related examples in the same category

1.Porter scanner
2.Ping server
3.Execute shell command 'dir'
4.Ping command
5.Execute help command and check its output
6.Using exec() to Produce a Directory Listing
7.Calling the man Command
8.Using popen() to Pass Data to the column Application