I have tried eval, system, exec, putting the script to a file and calling the file etc.. Nothing seems to work.. Here is the mod_perl2 module which is loaded into Apache at startup.. The URL I would send in this example is http://someserver/dashboardscripts?name=loop
package DashboardScripts::DashboardScripts; # File: DashboardScripts/DashboardScripts.pm use strict; use Apache2::RequestRec (); # for $r->content_type use Apache2::RequestIO (); # for $r->puts use Apache2::Const -compile => qw(OK DECLINED M_GET HTTP_METHOD_NOT_AL +LOWED); BEGIN { $| } use Data::Dumper; sub handler { my $r = shift; my $ref; my $post; #my $host = $r->get_remote_host; unless ($r->method_number == Apache2::Const::M_GET) { $r->allowed($r->allowed | (1<<Apache2::Const::M_GET)); return Apache2::Const::DECLINED; } $r->content_type('text/html'); map { $_ =~ s/\+/ /g; my ($key, $val) = split(/=/,$_,2); foreach ($key, $val) {$_ =~ s/%([A-Fa-f0-9]{2})/pack("c",h +ex($1))/ge}; $$ref{$key} .= (defined($ref->{$key})) ? "\0$val" : $val; } split/[&;]/,$r->args(); #mysql> desc defaultscripts; #+----------+-------------+------+-----+---------+-------+ #| Field | Type | Null | Key | Default | Extra | #+----------+-------------+------+-----+---------+-------+ #| name | varchar(25) | NO | PRI | | | #| script | text | YES | | NULL | | #+----------+-------------+------+-----+---------+-------+ #2 rows in set (0.01 sec) exit Apache2::Const::DECLINED if ($ref->{name} eq ""); my @Raw_DB_Data; my $dbh = DBI->connect("DBI:mysql:dashboards", 'id', 'passwd', { PrintError => 0, # warn( ) on errors RaiseError => 0, # don't die on error AutoCommit => 1, # commit executes immedi +ately } ); my $sql = "SELECT script FROM scripts where name='$ref->{name}'" +; my $script; my $sth = $dbh->prepare("$sql"); if ($sth->execute) { while(my $row_hash = $sth->fetchrow_hashref) { $script = "$row_hash->{script}"; + } $post .= "$script"; $post .= eval "$script; 1" or warn $@; $sth->finish(); } ################################################ $r->puts(<<"END"); $post END undef $post; undef $r; undef $sth; undef $dbh; return Apache2::Const::OK; } END { } 1;
When I pass the URL, I want it to parse the args (works) go to the database and get the perlscript, execute the script and output back to the module to display the results. Sounds simple enough however, it simply is not working.. I have two examples in the database.
#!c:/perl/bin/perl.exe use strict; for(my $x=0; $x<=100000;$x++){ print "$x<br>"; }
and
for(my $x=0; $x<=100000;$x++){ print "$x<br>"; }
The above prints the script that it got back from the db just fine. But only returns the 1 after. Ideas on what I might be doing wrong here. Thanks

In reply to Re^2: Executing code stored in a database.. by jbinaustin
in thread Executing code stored in a database.. by jbinaustin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.