OS: Ubuntu 16.04
I tried to use variable inside ssh2_exec but I get this message:
PID TTY TIME CMD 12585 pts/0 05:27:05 samp03svr bash: line 1: -o: command not found
My code:
include('Net/SSH2.php');
$cmd = "sudo ps -p {$user->sshConnect()} -o %cpu";
$ssh = new Net_SSH2('IP');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec($cmd);
sshConnect function:
public function sshConnect(){
$connection = ssh2_connect('IP', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'lsof -t -i :6000');
stream_set_blocking($stream, true);
$out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
return stream_get_contents($out);
}
But, if I replace {$user->sshConnect()} with my current PID, it works fine. Also $user->sshConnect(), return valid PID when I echo it.
Thanks.