Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

CGI-Perl: how to save data to file

by srinuperl (Initiate)
on Oct 23, 2014 at 08:37 UTC ( [id://1104749]=perlquestion: print w/replies, xml ) Need Help??

srinuperl has asked for the wisdom of the Perl Monks concerning the following question:

I have written CGI-Perl script which runs the remote command on the storage.Data available in the array.i would like to copy that data to file when user click the submit button and redirect ot next page. How to do that>>

Replies are listed 'Best First'.
Re: CGI-Perl: how to save data to file
by Discipulus (Canon) on Oct 23, 2014 at 09:08 UTC
    hello srinuperl,
    can I tell you that your question is very poor detailed?
    What have you tried? which part does not run as you expect?

    L*
    PS i have moved your question from Discussion to Seekers of Perl Wisdom, as i messaged to you.
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Sorry for not provided the complete info. I just want to explain the background of my script below... My basic Requirement is to create the web-based Runbook for the user using the CGI-Perl. 1.Configured the Apache and Perl on my unix system -->woring fine. 2.I have written the three CGI scripts. a)First script(cgi1.cgi) show the webpage which ask for the user input using textbox and radio buttons --> working fine. After user providing the input data(Storage name and Type of Request),he will click on the submit button. b)Second Script(cgi2.cgi) capture the input which was provided by the user in cgi1.cgi script and run the remote command on the storage box and display the output on the next webpage and display the "confirm" button at the end of webpage --> working fine. When user reviewed the output data on the wepage and click on "confirm" to save the output data to one file in the web server --> Not working. 3) Third script(cgi3.cgi),just display the info on the webpage with info "Runbook created successfully and saved in file" --> working. I m using the Onclick with subroute in my second script(cgi2.cgi) to save data in File.but it's not working. I have attached my script for more info.Please help..

      ---- #!/usr/bin/perl use strict; use warnings; use CGI; use Net::OpenSSH; our $ssh;our $KeyFile; my $obj;our $list;our @splitlist;my $eachline;our $date;our @splitdate +;our $choice;our $DrType;our @cmdout;our $command;our $user;our $host +;our @list1;our @uptime;our $eachhost;our @error;our $eachrelation;ou +r $eachvol;our @splitline;our $hostname;our $volpath;our $count;our @ +outarray;our @array; $date=`date`; @splitdate=split(" ",$date); $obj=new CGI; print $obj->header, $obj->start_html(-title=>'Output Of the Runbook'), $obj->center($obj->h2('RunBook Output')), $obj->start_form( -method=>'POST', -action=>'http://192.xxx.xxx.xxx/scripts/CreateAtt.cgi' ); $DrType=$obj->param('radio'), $choice=$obj->param('radio1'), $list=$obj->param('FilerList'), print "You enter DR Type: ", $obj->b($DrType), "<br><br>", "You Enter the Choice: " , $obj->b($choice), "<br><br>", "You Enter the Filer/Volume list is :", $obj->h4($list),"<br><br>"; @list1=split(/\s+/,$list); $count=0; if($choice eq "Filers") { foreach $eachhost(@list1) { chomp($eachhost), $ssh=Net::OpenSSH->new("$eachhost",user=>"sri",key_path=>"XXXX +"); @uptime=$ssh->capture("snapmirror status"); if(!@uptime) { print $ssh->error and die "On $eachhost cannot run the command"; }else{ foreach $eachrelation(@uptime) { next if($eachrelation=~m/^Snapmirror/); next if($eachrelation=~m/^Source/); chomp($eachrelation), $array[$count++]="$eachrelation<br>", print "$eachrelation<br>", } } } }else{ foreach $eachvol(@list1) { chomp($eachvol), @splitline=split(":",$eachvol), $hostname=$splitline[0],$volpath=$splitline[1], chomp($hostname),chomp($volpath), $ssh=Net::OpenSSH->new("$hostname",user=>"sri",key_pat +h=>"XXXX"); @uptime=$ssh->capture("snapmirror status $volpath"); if(!@uptime) { print $ssh->error and die "On $eachhost cannot run +the command"; }else{ foreach $eachrelation(@uptime) { next if($eachrelation=~m/^Snapmirror/); next if($eachrelation=~m/^Source/); chomp($eachrelation), $array[$count++]="$eachrelation<br>", print "$eachrelation<br>", } } } } print $obj->br(), $obj->br(), #$obj->center($obj->button(-name=>'Confirm',-value=>'Confirm',-onClick +=>"copy(@array)")), $obj->center($obj->submit(-name=>'Confirm',-value=>'Confirm',-onClick= +>"copy(@array)")); #$obj->end_form(), $obj->end_html(); sub copy { @outarray=@_; open(FH,">/home/srinu/scripts/textfile") or die "cannot write +to file"; print FH @outarray; close(FH); }

        I'm sorry, but "but it's not working" is not a good error description.

        Please tell us how it fails to work.

        Does your script get called?

        Does your script fail to create the file?

        Does your script exit with an error? If so, what is the error message?

        Does your script store the wrong data?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1104749]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found