Results 1 to 4 of 4
Help…
I have a webpage (php) and I want to call/execute a expect script (via shell if need be). I have tried PHP-exec, passthru, shell_exec, system, escapeshell etc to no ...
- 05-05-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 3
expect and shell: spawn command not found
Help…
I have a webpage (php) and I want to call/execute a expect script (via shell if need be). I have tried PHP-exec, passthru, shell_exec, system, escapeshell etc to no avail. (The best results are with passthru). The script is to telnet to a machine (with an argument), login, run a command and exit. When ran from a command line it runs great. I log the event to a file (in expect) and it appears that it connects to the equipment but I never get the “username” prompt to pop up.
In the webpage I call the script---
passthru(`/opt/xampp/htdocs/test/checkadd.sh $quote`);
When ran from command line it looks like this –
/opt/xampp/htdocs/test/checkadd.sh 72.123.36.19
spawn telnet 66.153.111.111
Trying 66.153. 111.111...
Connected to 66.153.111.111.
Escape character is '^]'.
User Access Verification
Username:theusername
password:
MachineName#1#show cable modem 72.123.36.19 verbose
No cable modem with IP address 72.123.36.19
MachineName#1#spawn telnet 66.153.222.222
Trying 66.153.222.222...
Connected to 66.153.222.222.
Escape character is '^]'.
User Access Verification
Username:htcbackup
Password:
MachineName#1#show cable modem 72.123.36.19 verbose
No cable modem with IP address 72.123.36.19
Checkadd.sh
#!/bin/sh
cd /opt/xampp/htdocs/test
/opt/xampp/htdocs/test/checkadd.exp $1
Checkadd.exp
#!/usr/local/bin/expect
#exp_internal 1
set modemmacadd [lindex $argv 0]
set ipadd1 66.153.111.111
set ipadd2 66.153.222.222
log_file -noappend "/opt/xampp/htdocs/test/log.txt"
#66.153.111.111 MachineName#1##############
spawn telnet $ipadd1
expect "Username:"
send "theusername\r"
expect "Password:"
send "thepassword\r"
expect "MachineName#1#"
send "show cable modem $modemmacadd verbose\r"
expect "MachineName#1#"
send "exit\r\n"
#66.153.222.222 MachineName#2##############
spawn telnet $ipadd2
expect "Username:"
send "theusername\r"
expect "Password:"
send "thepassword\r
expect "MachineName#2#"
send "show cable modem $modemmacadd verbose\r"
expect "MachineName#2#"
send "exit\r\n"
…
error.log
sh: spawn: not found
sh: Trying: not found
sh: Connected: not found
sh: Escape: not found
...
Contents of /opt/xampp/htdocs/test/log.txt
Trying 66.153.111.111...
Connected to 66.153.111.111.
Escape character is '^]'.
theusername
thepassword
show cable modem 72.123.36.19 verbose
Trying 66.153.222.222...
Connected to 66.153.222.222.
Escape character is '^]'.
theusername
thepassword
show cable modem 72.123.36.19 verbose
Trying 66.153.333.333...
- 05-05-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Why do you expect your web browser to act like a terminal? The reason why it worked from the command line is that you are on a terminal, or terminal emulator such as xterm, kterminal, or whatever. You need to research how to access the stdin/sdtout/stderr streams from a spawned shell command within a web browser, because the stdout is what you need to intercept and relay to the user, the stdin is what you need to pipe their input (userid/password) to, and stderr is what you need to relay for errors spawned by the shell and processes it runs.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-06-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 3
Thank you, Rubberman, for you comments.
I think we are on the same page in general. One of the things I pointed out is that the expect script is logging in but not returning a prompt for "username". What I think is happening is the #!/bin/sh is responding to the expect being performed in expect program.
I think the fix is a minute quick one that I am not seeing. Do you have a more "specific" suggestion other than "research how to access the stdin/sdtout/stderr streams from a spawned shell command".
- 05-09-2009 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
FIrst a question. Are you using CGI scripts to do this? Or are you using something like JSP or ASP scripting?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote