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?


ednitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rootkiddyCommented:
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.
0
ednitAuthor Commented:
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.
0
rootkiddyCommented:
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.

#!/usr/local/bin/perl

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rootkiddyCommented:
How's the script going?  Did you need any further assistance?
0
ednitAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.