Solaris,PHP,Expect support | Unix Linux Forums | Solaris

  Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Solaris,PHP,Expect support

Solaris


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-27-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 1 May 2014, 1:48 PM EDT
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
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
Sponsored Links
    #2  
Old 01-28-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 8 July 2014, 12:19 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,378
Thanks: 8
Thanked 535 Times in 514 Posts
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.
Sponsored Links
    #3  
Old 01-28-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 1 May 2014, 1:48 PM EDT
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
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

Code:
  <?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);
?> 


Last edited by Scott; 01-28-2013 at 07:37 PM.. Reason: Code tags, please...
    #4  
Old 01-28-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 8 July 2014, 12:19 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,378
Thanks: 8
Thanked 535 Times in 514 Posts
Usually fopen() is for accessing flat file data. What worked interactively?
Sponsored Links
    #5  
Old 01-28-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 1 May 2014, 1:48 PM EDT
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
When i run the below script from a command line it works fine but i guess the next step is integrating it into php.


Code:
#!/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


Last edited by Scott; 01-28-2013 at 07:35 PM.. Reason: Code tags
Sponsored Links
    #6  
Old 01-28-2013
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 24 July 2014, 10:15 AM EDT
Location: Asia pacific region
Posts: 12,989
Thanks: 513
Thanked 868 Times in 397 Posts
Power

Quote:
Originally Posted by DGPickett View Post
Usually fopen() is for accessing flat file data. What worked interactively?
OBTW fopen() is used for both flat files and URLs. Here are some examples:

PHP Code:
<?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");
?>
Sponsored Links
    #7  
Old 01-29-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 8 July 2014, 12:19 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,378
Thanks: 8
Thanked 535 Times in 514 Posts
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.

Last edited by DGPickett; 01-29-2013 at 09:50 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
EXPECT script for Telnet automation. Need your support. starchen Shell Programming and Scripting 2 08-12-2011 11:09 AM
configure php with mcrypt support pupp Shell Programming and Scripting 1 10-11-2008 01:03 PM
Run expect script in systems that don't support it out of box namityadav Shell Programming and Scripting 1 04-19-2006 08:06 PM



All times are GMT -4. The time now is 11:20 AM.