Post data from one server to another using cron

Posted on 2003-11-09
Last Modified: 2012-06-21
I am having trouble getting this to work, but maybe it's not possible that's why it's not workin. . .

I have website a with this as the sending script:


require "config.cgi";

print "content-type: text/html\n\n";

open (list, "<$MAILING_LIST") or &NO_OPEN("subscribers.txt missing");if ($flock eq "y") {flock list, 2; }@list=<list>;close(list);$Emails=0;foreach $list(@list) {$Emails++;}

print qq~
<body onLoad="document.this.submit()">

<form name="this" method="post" action="">
<input type="hidden" name="email" value="$Emails"></form>


It works to submit when I load it manually. . . but doesn't seem to work with cron.

Here's what it's submitting to(at a different location):

if ($ENV{'REQUEST_METHOD'} eq "GET") {
$buffer = $ENV{'QUERY_STRING'};
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$form{$name} = $value;
$ad = 1;
@bla = split("=",$buffer);
$table = "members";
$total = "SELECT COUNT(*) FROM $table WHERE list_verified='yes'";
$tm = $dbh->prepare($total);
while ($result = $tm->fetchrow_array) { $total_ver = $result; }
$table = "members";
$total2 = "SELECT COUNT(*) FROM $table WHERE mem_type='Gold' AND want_mail='yes'";
$tm = $dbh->prepare($total2);
while ($result = $tm->fetchrow_array) { $total_gold= $result; }
$mailing = $total_ver+$total_gold+$bla[1];
$dbh->do("UPDATE admin SET send_to=$mailing WHERE main_a=$ad");

These are both set to run every minute. . . but only work when manually loaded. . .(from the first script. . .) is there something I can do to make this work?

Question by:ednit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 9712240
When you say manual loading are you referring to this cgi script being on a website and you calling the page?  As the code you pasted would only call submit if a browser interpretted the output that you printed to it (e.g. <body onLoad="document.this.submit()">).  From cron or just from the commandline you would only be getting the printed output and it not submitting unless you meant to post some other code.

Now if you didn't have some other code what you may be trying to do is implement a useragent using something like LWP from perl.  Documentation on it is at

Another thing you might be able to do is leave that cgi script on the webserver and then use lynx in cron to call the cgi script.  Lynx would be the useragent to interpret and execute the Onload.  I'm not absolute of lynx will do that for you or not.

If I have misunderstood what you are trying to do or you have other code to look at please post it and I'll look further.

Author Comment

ID: 9712366
I am really not sure what it's doing. . . I only half know what I'm doing really. . .

What I mean by manually loading is I type the address into the browser window and the page loads. . .(I forgot the <input type="submit. . . .) I was messing around with it a whole lot trying different things.  From the cron command line I was using  /home/mydomain/public_html/list/cgi-bin/total.cgi. . . When I had the "total.cgi" configured properly & I called it up (manually) it sent the info to the other server to the "tt.cgi" and updated the database there, which in turn updated the information on the site.  I have heard of LWP but am just starting to learn perl. . . and as for lynx, I have never heard of it.  I will check into  LWP and lynx. . . if I have shared something that'll help you to help me, I'm all ears.  Otherwise I will check those out in the next couple of days. . .

Thanks for the input.

Accepted Solution

rootkiddy earned 400 total points
ID: 9712559
Well if you want to just start playing with LWP and replace your script you can start by using the simplest thing which is write the script to run from cron to call your webserver.  After you get comfortable with that then you can change the method to a POST and start adding in all your form data.  The code below is exact from the website  I didn't write your script  for you as it sounded like you are interested in learning it.  If you need more assistance I will be glad to help.  To get the below code to work you will need to have LWP installed and replace the "file://localhost..." with the URL that you used to call your script from your web browser.  And of course you need to change the #!/usr/local/bin/perl with the location of perl.


require LWP::UserAgent;
$ua = LWP::UserAgent->new;
$request = HTTP::Request->new('GET', 'file://localhost/etc/motd');
$response = $ua->request($request);

Expert Comment

ID: 9747630
How's the script going?  Did you need any further assistance?

Author Comment

ID: 9760018
I have not started trying it yet. . . but will need to in the next week.  I will post back if more input is needed. . . thank you for your help.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question