Solaris,PHP,Expect support

Hello All,

I installed php5 from OpenCSW but i believe it does not support the expect module.
I tried to run a php script to call expect to do a telnet to a device but i got this error

PHP Warning: fopen(): Unable to find the wrapper "expect" - did you forget to enable it when you configured PHP? in /export/home/php_expect.php on line 5

I will appreciate very much if you can help me configure the expect wrapper into php.

Thanks

It sounds like you are missing environment for expect in the web service. Your expect may need some additional exported variables before it is called. Maybe it is in the wrong working directory to run.

Well this is the script i was trying to run to test if i could use expect. Can you suggest how i can export these environment variables. Thanks

  <?php
ini_set("expect.loguser", "Off");

$stream = fopen("expect://ssh root@remotehost uptime", "r");

$cases = array (
    array (0 => "password:", 1 => PASSWORD)
);

switch (expect_expectl ($stream, $cases)) {
    case PASSWORD:
        fwrite ($stream, "password\n");
        break;
 
    default:
        die ("Error was occurred while connecting to the remote host!\n");
}

while ($line = fgets($stream)) {
      print $line;
}
fclose ($stream);
?> 

Usually fopen() is for accessing flat file data. What worked interactively?

When i run the below script from a command line it works fine but i guess the next step is integrating it into php.

#!/opt/csw/bin/expect -f
spawn ssh me@localhost          
expect -exact "me@localhost password:"            
send "enternow  
"
expect "me@localhost:~$"          
send "uname -a
"
expect "me@localhost:~$"          
send "exit
"
expect eof

OBTW fopen() is used for both flat files and URLs. Here are some examples:

<?php
$file = fopen("test.txt","r");
$file = fopen("/home/test/test.txt","r");
$file = fopen("/home/test/test.gif","wb");
$file = fopen("http://www.example.com/","r");
$file = fopen("ftp://user:password@example.com/test.txt","w");
?>

I learn more each day. Of course, it it cannot make it go as either, it will fail.

Put a wrapper shell script around it to allow you to run a .profile or export VAR=VALUE to restore the env you have where it works (things displayed by set). A wrapper can also log details of the failure using strace/truss/tusc.