ssh2_exec is not working
I have script that using to ssh2 to log into the firewall. I would like to run the commands from the firewall as if I was in the terminal when I add in the command in my script I get Resource id #5.
<?php
$connection = ssh2_connect('192.168.2.5', 22);
ssh2_auth_password($connection, $user, $pass);
$stream = ssh2_exec($connection, 'get hardware cpu',FALSE);
$check=stream_get_contents($stream);
echo $check;
echo $stream;
?>
Related Article: urlencode is not working php
is a PHP discussion thread by sahil.bhatia.18 that has 1 reply and was last updated 2 months ago.
tapuwa2002
Junior Poster in Training
56 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
I have script that using to ssh2 to log into the firewall. I would like to run the commands from the firewall as if I was in the terminal when I add in the command in my script I get Resource id #5.
You can't run the command from the terminal by using php?
Who told you that it will work?
It doesn't work like that if you want to work from the terminal then read this:
http://opensuse-guide.org/command.php
If you just have problems connecting ssh2 function read this:
http://www.nusphere.com/kb/phpmanual/function.ssh2-connect.htm
This is how you put the info:
$ssh->connect('your server', 22, 'username', 'somepasswd');
not this:
$connection = ssh2_connect('192.168.2.5', 22);
If you still have issue then try this:
On your ini file or httpd.conf do you see these
ssh2.shell
ssh2.exec
ssh2.tunnel
ssh2.scp
ssh2.sftp
If not restart your Apache
LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45