on HTML form, Call Expect in Perl problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting on HTML form, Call Expect in Perl problem
# 1  
Old 02-05-2010
on HTML form, Call Expect in Perl problem

Hi

I have a successfullly run perl script (by issuing command "perl sub.pl" under shell mode) and this sub.pl will call sub.exp successfully. The sub.exp expect script is basically to login to a server and run some commands and put the output into a sub.txt file, it takes about 5 seconds to complete the sub.exp and the sub.txt is generated. The sub.pl is basically display the sub.txt on a TEXTAREA on a HTML form.

Now, I am using POST method on a HTML form. I want to press a buttom to call the perl script. I found that if the sub.txt already exists, the sub.pl is able to display content of sub.txt on the TEXTAREA without any problem, but if there is no sub.txt exists, sub.txt will not be generated and will not be displayed on TEXTAREA if I press the buttom which calls the sub.pl.

Can someone help please?

Here is the code of HTML

Code:
...
<FORM METHOD="POST" ACTION="sub.pl"> 
<INPUT TYPE="Submit" VALUE="sub"> 
</FORM>
...

Here is the code of sub.pl

Code:
 
#!/usr/bin/perl
 
system('expect /opt/xampp/htdocs/hsgw/sub.exp');
 
print "Content-type:text/html\n\n";
print "<html>\n";
print "<head><title></title></head>\n";
print "<body>\n";
print "<textarea cols=150 rows=30>\n";
open(INFO, "sub.txt");
@array=<INFO>;
close (INFO);
chomp(@array);
foreach $line (@array){
print "$line\n";
}
print "</textarea>\n";
print "</body>\n";
print "</html>\n";

Here is the code of sub.exp

Code:
#!/opt/corp/unsupported/bin/expect
 
set timeout 5
set sub [lindex $argv 0]
set dfile "sub.txt"
set rhost X.X.X.X
set rlogin admin
set rpass admin
match_max 100000
spawn telnet $rhost
expect "*login:    "
send -- "$rlogin\r"
expect "*password: "
send -- "$rpass\r"
expect  "*XXX-1# "
set file [open $dfile w]
send -- "show sub all\r"
expect {
 "*XXX-1#" {
  set stuff "$expect_out(buffer)"
  puts $file $stuff
  close $file
 }
 timeout {
  set stuff "$expect_out(buffer)"
  puts $file $stuff
  close $file
  exit
 }
}
sleep 10
send -- "exit\r"
expect eof



---------- Post updated at 01:30 PM ---------- Previous update was at 01:24 PM ----------

And I checked access_log, there is an entry recorded after I press the buttom,

Code:
x.x.x.x - - [05/Feb/2010:13:28:42 -0500] "POST /hsgw/sub.pl HTTP/1.1" 200 99



---------- Post updated at 03:55 PM ---------- Previous update was at 01:30 PM ----------

Can anybody let me know is that technically possible to implement the program with only HTML form, perl and expect?
This User Gave Thanks to cxbest For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Html form to submit data to bash script

hi all, im going to design a web html form so users can input what username and password they want to make the ftp account, once they enter in a username and password they click on the submit button and it submits it to a bash script and then the bash script will run and finish of making the... (3 Replies)
Discussion started by: robertkwild
3 Replies

2. Shell Programming and Scripting

pass argument to html upload form

I am using an html form and a php upload script to upload files. HTML form <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table... (1 Reply)
Discussion started by: anil510
1 Replies

3. Shell Programming and Scripting

MySQL bulk retrieval of database through html form

Have to delete this long post. Seems nobody would spent time on it. (0 Replies)
Discussion started by: yifangt
0 Replies

4. Solaris

man pages in html form

Hi I would like to convert standard online man pages from my solaris10 system into html form to publish it on my webpage. How this can be done in Sol10 ? thx for help. (2 Replies)
Discussion started by: presul
2 Replies

5. Shell Programming and Scripting

Pass variable to php from html form

I am sure this is easy but I can't figure it out... Here is the form. <?php $searchString = $_POST; if (!isset($_POST)) ?> <html> <head> <title>Personal INFO</title> </head> <body> <form method="post" action="search.php"> <input type="text" size="20" maxlength="20" name="search">... (1 Reply)
Discussion started by: mrlayance
1 Replies

6. Shell Programming and Scripting

How to call expect script from Perl

I have a Perl script sub.pl, and i want to call another Expect script called sub.exp. The sub.exp will generate a text file called sub.txt, while the sub.pl called from a html form will display the content of sub.txt to the textarea on the html form. How do I call sub.exp from sub.pl??? ... (5 Replies)
Discussion started by: cxbest
5 Replies

7. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

8. Shell Programming and Scripting

Converting %## back to special characters from an HTML form

I have an HTML form that sends email to a large list of users one at a time by matching an email address in peoplesoft to their username. It works great, except that special characters are converted to %## format. Is there a library of these I can use to sed them back (yes this is a crappy UNIX... (1 Reply)
Discussion started by: 98_1LE
1 Replies

9. Shell Programming and Scripting

HTML form to cgi help

I wrote a script to automate user account verification against peoplesoft. Now I want to make it available to my peers via the web. It is running on Solaris. I have the form written, but am not sure how to make it work. I think the form should call a perl cgi when submitted. The cgi should call... (7 Replies)
Discussion started by: 98_1LE
7 Replies

10. Shell Programming and Scripting

Passing FORM(HTML) variable to ksh

I am currently able to use the $QUERY_STRING variable and simply cut out what I need to be assigned as variables within the shell script. However, I've been able to use the "name" value assigned within the FORM(HTML) as a variable when I use perl. Why is it that ksh doesn't read the "name" in as... (1 Reply)
Discussion started by: douknownam
1 Replies
Login or Register to Ask a Question