Expect Script through Putty works but not when called by scripts executed via http

1.6k views Asked by At

I have an expect script that connects to one of our remote servers, it runs a few commands as admin then exits. When i run the script through the Putty CLI it works properly. However when I call the script via http it fails, the script isn't presented with the valid data. (Below)

I've been working away at this and have broken it down to it's most basic level to rule everything out:

I run test.php that calls the expect script:

echo shell_exec("expect bwvtr.exp HOST USER PASS CLIUSER CLIPASS SOURCE DEST");

and when run through putty (ssh'd to management server) it connects to the network server and functions properly.

======================================================================
BroadWorks Command Line Interface
  Type HELP for more information
======================================================================
Reading initial CLI command file...

NS_CLI> l CLIUSER
Password:
Administrator,Administrator logging in...

NS_CLI> vtr +1SOURCE DEST

However when I call the script from the web host I get

======================================================================
BroadWorks Command Line Interface
  Type HELP for more information
======================================================================
Reading initial CLI command file...
[?1h

[?1l[?1h

[?1l[?1h

[?1l[?1h

[?1lExiting the CLI ...
[?1l]0;
  1. I've tried just sending the next commands after the timeout but that doesn't work either. The script sends the \003 (Ctrl+c) to exit properly.
  2. I've changed the local server ssh settings to not send any environment variables. Putty still works, http still fails.
  3. I've compared the SSH sessions via ssh -v and they are identical.
  4. I've set the Locale and lang varibles to UTF-8, no change.

Has anyone come across this before?

1

There are 1 answers

0
Rob22 On BEST ANSWER

By setting the stty cols to 200 and rows to 100 i was able to receive output:

By adding the following after the spawn ssh and login, but before any other commands:

expect "$ "
send "stty cols 200\r"

expect "$ "
send "stty rows 100\r"