Link to home
Start Free TrialLog in
Avatar of ednit
ednit

asked on

Post data from one server to another using cron

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:

#!/usr/bin/perl

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>
</body>

~;


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);
&OPENdb;
&get_members;
$table = "members";
$total = "SELECT COUNT(*) FROM $table WHERE list_verified='yes'";
$tm = $dbh->prepare($total);
$tm->execute;
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);
$tm->execute;
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");
&CLOSEdb;


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?


Avatar of rootkiddy
rootkiddy

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.
Avatar of ednit

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of rootkiddy
rootkiddy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How's the script going?  Did you need any further assistance?
Avatar of ednit

ASKER

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.