I'm trying to get some commands executed on a distant device. I'm using public and private key to connect to distant device. 

In my server i have just to type : ssh username@distant\_device command and i get the result of it. So i want to do this throught a php page.

I tried different methods and it didn't work for me.

1 - 

```
 $cmdline = escapeshellcmd("ssh username@distant_device command");
 system($cmdline);

```

2 - executing shell script in the server 

script.sh : 

```
#!/bin/bash

output=$(ssh username@distant_device command)
echo "$output" >> test.txt

exit 0

```

php code :

```
passthru('./script.sh',$result);
echo $result ;

```

I got result sending by my script but not the result of the ssh command in it. When i execute the script directly i have the result.

3- 

```
system ("ssh username@distant_device command > test.txt");
system ("ssh -i /home/nagios/.ssh/id_rsa -o 'StrictHostKeyChecking no' username@distant_device command' > test.txt");

```

text file remain empty 

What i'am doing wrong ?