Jump to content

exec appears to chop up the commands I give it - formatting/syntax/buffer error?


miseleigh

Recommended Posts

We're using php to run batch files that create an ssh connection (using PuTTY) into routers and run various commands on those routers.  At least, that's what we're trying to do, but somewhere along the way the commands for the router get partially lost.

 

The code that creates & executes the batch file:

$cmd.="$cmd="set PATH=D:\Program Files\PuTTY;%PATH%\r\n";
plink $rt -ssh -l $un -pw $pw < $script\r\n"; //plink is the putty connect command
//$rt is the router's ip, $script is a file holding the ssh commands for the router
$bat=$folder."putty.bat";
$fp=fopen($bat, 'w');
fwrite ($fp, $cmd);
fclose ($fp);
exec ($bat." >> ".$out);

 

The batch file is exactly what we need it to be, and works well when you double-click it.  However, when run through exec... basically, the first half of the router commands in the $script file get cut out.

The .bat file (which works perfectly on it's own, btw): ($bat, above)

set PATH=D:\Program Files\PuTTY;%PATH%
plink ipaddress -ssh -l username -pw password < routerfile.txt

And then routerfile.txt:

enable

config

remote configuration radius

interval 43200

end

end

quit

And the output (from the $out file in the exec command):

prompt>set PATH=path

prompt>plink ipaddress -ssh -l username -pw password  0<C:/OpenSA/Apache2/MMW_Includes/SSH/interval720.txt

ation radius

interval 43200

end

end

quit

 

MSC-3200 V. 3.1.1.5-03-4687

© 2005 Colubris Networks Inc.

CLI> ation radius

% Unknown command.

CLI> interval 43200

% Unknown command.

CLI> end

% Unknown command.

CLI> end

% Unknown command.

CLI> quit

(where CLI> is the router's prompt.)

As you can see, the router isn't receiving "enable config remote configur" when it should, but again this is only when we run the batch file through exec.  I've also tried using system instead of exec, with the same results.

The only things I've been able to think that might do this would be overrunning a buffer somewhere, or maybe it's not waiting for the router's prompt before it starts sending commands, or there's an Apache or PHP configuration issue.

 

I would love some help if anyone knows what's going on here, or at least has some suggestions for where to look.  Thanks.

Link to comment
Share on other sites

Yet another update... this is really bugging me now.

 

exec is partly working, but not fully.  Doing an exec command on a process like solitaire or calculator does create a process, but the window won't pop up - it seems to get hung right after the process is started but before it really gets going.  It's probably not a php issue like I thought it was, but I'm still hoping someone here can help because I really don't know where else to go.  We've been working on this for a few days now and haven't gotten anywhere.

 

Thanks for any help/advice you can offer.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.