Error running expect script from PHP. Please help!
Posted: Fri Jan 23, 2004 9:45 am
Hi,
I´m using a simple tclsh expect script for connect to a remote host in order to run a remote command and present the result from a PHP page using ActiveTcl package. The tcl script is:
#!/usr/local/ActiveTcl/bin/tclsh
package require Expect
set USER <my_user>
set PASS <my_password>
set SISTEMA <host_ip>
set COMMAND [ lindex $argv 0 ]
set OPTION [ lindex $argv 1 ]
set LOG logfile.log
set BOX host
set env(TERM) vt100
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout 60
log_user 1
spawn /usr/bin/telnet $SISTEMA
match_max 100000
expect -exact {
"login: " {
send -- "$USER\r"
}
timeout {send_user "Timeout login";exit}
}
expect {
"Password:" {
send -- "$PASS\r"
}
timeout {send_user "Timeout password";exit}
}
expect {
"> " {
send -- "./$COMMAND $OPTION
;'\r"
}
timeout {send_user "Timeout command";
exit}
}
expect {
"not found" {send_user "ERROR NOT FOUND";exit}
"> " {
send -- "exit\r"
}
timeout {send_user "Timeout Line";exit}
}
expect "closed"
This script is setuid using "chmod 4550 <script> " and "chown user:nobody script", so you can
access
from the PHP page with Apache running as nobody an run this script.
When i run it from a unix shell, it run OK, but when i run it from a PHP page using exec
('/export/home/tel-con.sh',$result,$error); it fail, giving a timeout error when waiting fo
r the
remote "login:". When i print the variable $result i can see.
spawn /usr/bin/telnet <remote-host-ip>
Trying 10.40.2.48...
Connected to <remote-host>
Escape character is '^]'.
Timeout login
It seem like if the tclsh script don´t recive the remote login. So, it seem to be a bug on A
ctiveTcl
because when I run this script from PHP with expect-5.39 and tcl-8.4.4 installed it run OK.
Can you help me!!!!
Thanks for your time!
Jesus
I´m using a simple tclsh expect script for connect to a remote host in order to run a remote command and present the result from a PHP page using ActiveTcl package. The tcl script is:
#!/usr/local/ActiveTcl/bin/tclsh
package require Expect
set USER <my_user>
set PASS <my_password>
set SISTEMA <host_ip>
set COMMAND [ lindex $argv 0 ]
set OPTION [ lindex $argv 1 ]
set LOG logfile.log
set BOX host
set env(TERM) vt100
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout 60
log_user 1
spawn /usr/bin/telnet $SISTEMA
match_max 100000
expect -exact {
"login: " {
send -- "$USER\r"
}
timeout {send_user "Timeout login";exit}
}
expect {
"Password:" {
send -- "$PASS\r"
}
timeout {send_user "Timeout password";exit}
}
expect {
"> " {
send -- "./$COMMAND $OPTION
;'\r"
}
timeout {send_user "Timeout command";
exit}
}
expect {
"not found" {send_user "ERROR NOT FOUND";exit}
"> " {
send -- "exit\r"
}
timeout {send_user "Timeout Line";exit}
}
expect "closed"
This script is setuid using "chmod 4550 <script> " and "chown user:nobody script", so you can
access
from the PHP page with Apache running as nobody an run this script.
When i run it from a unix shell, it run OK, but when i run it from a PHP page using exec
('/export/home/tel-con.sh',$result,$error); it fail, giving a timeout error when waiting fo
r the
remote "login:". When i print the variable $result i can see.
spawn /usr/bin/telnet <remote-host-ip>
Trying 10.40.2.48...
Connected to <remote-host>
Escape character is '^]'.
Timeout login
It seem like if the tclsh script don´t recive the remote login. So, it seem to be a bug on A
ctiveTcl
because when I run this script from PHP with expect-5.39 and tcl-8.4.4 installed it run OK.
Can you help me!!!!
Thanks for your time!
Jesus