On the HTML side you will need a form and submit button to run the update script.

<form method="POST" action="http://somesite.com/cgi-bin/script.pl"> <input type="Submit" value="Update"> </form> # for the script #!/usr/bin/perl -w use CGI; use Fcntl qw(O_WRONLY O_CREAT O_EXCL); my $q = new CGI; my $lockfile = '/tmp/lock'; if (sysopen(FH, $lockfile, O_WRONLY | O_CREAT | O_EXCL)) { # sysopen will only work if lockfile does not exist # exec the script and wait for it to complete using bacticks or ex +ec `your_update_script`; close FH; unlink $lockfile or error("<h3>Can't unlink lockfile $lockfile $!< +h3>"); print $q->redirect('http://page_to_display_after_update'); } else { error("<h3>Update already in progress!</h3>"); exit; } sub error { print $q->header, shift; }

Note that there will be collisions with your cron job unless you write a similar short lockfile script and exec that from cron like:

#!/usr/bin/perl -w use Fcntl qw(O_WRONLY O_CREAT O_EXCL); my $lockfile = '/tmp/lock'; if (sysopen(FH, $lockfile, O_WRONLY | O_CREAT | O_EXCL)) { `your_update_script`; close FH; unlink $lockfile or die "Can't unlink lockfile $lockfile $!"; print "Updated"; } else { die "Update already in progress. Aborting!"; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: CGI Question - run external script and then update page by tachyon
in thread CGI Question - run external script and then update page by Limbic~Region

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.