Unable to get output from exec "ssh remote-server "ping -c4 ip""

Unable to get output from exec "ssh remote-server "ping -c4 ip""

am 27.12.2009 22:53:01 von Robert Mena

--00163683269c12e612047bbcd0b7
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I need to develop an interface that will, for example, ping IPs from a
remote server. So the php script will be hosted in a server with ssh access
(key) to the remote server.

I can make it work from the console but when I try

$cmd = "ssh remote-server 'ping -c 4 ip'"
exec($cmd, $ouput);

the output is empty.

the same command (with the remote-server and IP changed to the real ones)
works fine from command line.

I've added the key/config in the webserver's user .ssh directory so I am
assuming that that there is something wrong with my setup.

any ideas?

--00163683269c12e612047bbcd0b7--

Re: Unable to get output from exec "ssh remote-server "ping-c4 ip""

am 28.12.2009 01:37:13 von Michael Kjeldsen

On 12/27/2009 10:53 PM, robert mena wrote:
> Hi,
>
> I need to develop an interface that will, for example, ping IPs from a
> remote server. So the php script will be hosted in a server with ssh access
> (key) to the remote server.
>
> I can make it work from the console but when I try
>
> $cmd = "ssh remote-server 'ping -c 4 ip'"
> exec($cmd, $ouput);
>
> the output is empty.
>
> the same command (with the remote-server and IP changed to the real ones)
> works fine from command line.
>
> I've added the key/config in the webserver's user .ssh directory so I am
> assuming that that there is something wrong with my setup.
>
> any ideas?
>

Probably other ways to do it, but this seems to work:

[michael@archie ~]$ php a.php
259

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.518 ms

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.518/0.518/0.518/0.000 ms

[michael@archie ~]$ cat a.php
$stuff = `ssh management 'ping -c 1 192.168.1.1'`;
echo strlen($stuff) . "\n\n$stuff";

- m

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Unable to get output from exec "ssh remote-server "ping -c4

am 30.12.2009 01:02:21 von Adam Randall

--00504502cbf44b352f047be6dab8
Content-Type: text/plain; charset=UTF-8

If you are just checking to see if the IP is pingable, but don't care about
the output you could just test against the exit code:

$host = 'hostorip';
$sshhost = 'hostorip';
$alive = trim( shell_exec( 'ssh ' . $sshhost . ' ping -q -n -c 5 -W 2 ' .
$host . ' \>/dev/null 2\>\&1 \&\& echo "Alive"' ) ) == 'Alive';
var_dump( $alive );

I use a variant of the above with good success on Gentoo.

Adam.

On Sun, Dec 27, 2009 at 1:53 PM, robert mena wrote:

> Hi,
>
> I need to develop an interface that will, for example, ping IPs from a
> remote server. So the php script will be hosted in a server with ssh access
> (key) to the remote server.
>
> I can make it work from the console but when I try
>
> $cmd = "ssh remote-server 'ping -c 4 ip'"
> exec($cmd, $ouput);
>
> the output is empty.
>
> the same command (with the remote-server and IP changed to the real ones)
> works fine from command line.
>
> I've added the key/config in the webserver's user .ssh directory so I am
> assuming that that there is something wrong with my setup.
>
> any ideas?
>



--
Adam Randall
http://www.xaren.net
AIM: blitz574
Twitter: @randalla0622

--00504502cbf44b352f047be6dab8--

Re: Unable to get output from exec "ssh remote-server "ping -c4

am 30.12.2009 04:56:39 von kranthi

better try using ssh2_* functions

http://www.php.net/manual/en/function.ssh2-tunnel.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Unable to get output from exec "ssh remote-server "ping -c4

am 07.01.2010 09:21:12 von hack988 hack988

see this
http://www.phpclasses.org/browse/package/4282.html

2009/12/28 robert mena :
> Hi,
>
> I need to develop an interface that will, for example, ping IPs from a
> remote server. So the php script will be hosted in a server with ssh access
> (key) to the remote server.
>
> I can make it work from the console but when I try
>
> $cmd = "ssh remote-server 'ping -c 4 ip'"
> exec($cmd, $ouput);
>
> the output is empty.
>
> the same command (with the remote-server and IP changed to the real ones)
> works fine from command line.
>
> I've added the key/config in the webserver's user .ssh directory so I am
> assuming that that there is something wrong with my setup.
>
> any ideas?
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php