I've tried parsing a list of users currently connected via SSH to a server, but the results are very irregular, so I was forced to simply do:
$users = shell_exec('who');
echo "<pre>$users</pre>";
Is there a better way to parse the output of who
in the command line before I let PHP mess around with it? I want it in an array which contains the username (first column below), the terminal they're connected on (second column), the date and time they connected (third), and the IP from where they connected (in parenthesis). I'm guessing I should use preg_split
to split the data but it seems really irregular sometimes with username length, terminal name, etc..
(some example output of who
):
alex tty7 2010-01-23 17:04 (:0)
alex pts/0 2010-01-30 17:43 (192.168.1.102)
root pts/1 2010-01-30 17:45 (192.168.1.102)