Go Premium for a chance to win a PS4. Enter to Win


Post data from one server to another using cron

Posted on 2003-11-09
Medium Priority
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="http://www.whatever.com/mysub/cgi-bin/mem/tt.cgi">
<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
  • 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 http://www.perldoc.com/perl5.6/lib/LWP/UserAgent.html.

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 1600 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 http://www.perldoc.com/perl5.6/lib/LWP/UserAgent.html.  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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

886 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