0

I am executing a bunch of ssh commands with php's exec. All of them seems to work correctly except one of them:

$command = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@127.0.0.1 "verify /md5 filename"';
exec($command, $output);

These commands are being executed on a Cisco router if that makes any difference.

The output is about 99% completed however it gets cut off at the end. I don't receive the last line at all and the second to last line always gets cut off after the 1st character. I also tried passtru and got the same results.

I've also tried adding 2>&1 to the end of the command and it made no difference. Anyone know what is going on here or have any ideas?

Here are the last 2 lines. This is what I expect:

..........Done!
verify /md5 (flash:filename) = 8743b52063cd84097a65d1633f5c74f5

I get

.

Also, running this on command line works perfectly. I have seen others with similar issues but there wasn't really any solution. This is on php 5.3.3.

I have a little more information to add to this. I created a separate script that only called the exec and this command and got the same output. This rules out any thing else in my file or the framework I'm using.

I also ran the new script from command line and it worked perfectly. Running the script in the browser however returns the bad results.

I can verify that it has something to do with how the data is being returned and those dots. The ...... must load in a way that PHP doesn't like and it thinks the command is done.

Keith
  • 1,352
  • 3
  • 21
  • 48
  • Could you show the last 3 lines of the expected output as if you were to run it in the shell? Maybe that could give hints as to what php exec doesn't like starting with the 2nd character of the 2nd to last line. – Jerome Oct 16 '14 at 18:10
  • 1
    Try using passthru() instead of exec() and see if that returns all the data for you. – Chad Oct 16 '14 at 18:10
  • Jerome, I updated it. cwscribner I'll try that – Keith Oct 16 '14 at 18:13
  • cwscribner, passthru returns the same thing. I should note that running this exact same command works perfect running on command line manually. – Keith Oct 16 '14 at 18:17
  • Does `uname` for example returns the actual value? Also, you could try to use full path - to determine it you can use `which verify`. Is 127.0.0.1 just for the example? Because if you're connecting to the same machine ssh connection would just be overhead. – Stanimir Stoyanov Oct 16 '14 at 18:32
  • Yes uname seems good. 127.0.0.1 is just an example, like I said I'm connecting to Cisco routers. – Keith Oct 16 '14 at 18:48
  • Check these answers http://stackoverflow.com/questions/3099617/php-capturing-the-command-output http://stackoverflow.com/questions/16665041/php-why-isnt-exec-returning-output – cjdaniel May 13 '16 at 15:10

0 Answers0