Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-27-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 March 2015, 4:26 PM EST
Posts: 20
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 Unix and Linux 01-28-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 February 2015, 1:56 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,671
Thanks: 8
Thanked 586 Times in 559 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 Unix and Linux 01-28-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 March 2015, 4:26 PM EST
Posts: 20
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 Unix and Linux 01-28-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 February 2015, 1:56 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,671
Thanks: 8
Thanked 586 Times in 559 Posts
Usually fopen() is for accessing flat file data. What worked interactively?
Sponsored Links
    #5  
Old Unix and Linux 01-28-2013
kaf3773 kaf3773 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 March 2015, 4:26 PM EST
Posts: 20
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 Unix and Linux 01-28-2013
Neo's Unix or Linux Image
Neo Neo is online now Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 18 April 2015, 3:02 AM EDT
Location: Asia pacific region
Posts: 13,144
Thanks: 627
Thanked 967 Times in 442 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 Unix and Linux 01-29-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 February 2015, 1:56 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,671
Thanks: 8
Thanked 586 Times in 559 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 03:14 AM.