Solved

Post data from one server to another using cron

Posted on 2003-11-09
5
492 Views
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:

#!/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?


0
Comment
Question by:ednit
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:rootkiddy
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.
0
 

Author Comment

by:ednit
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.
0
 
LVL 2

Accepted Solution

by:
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 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
 
LVL 2

Expert Comment

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

Author Comment

by:ednit
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Tutorial 6 127
perl script 4 94
Perl - Mawk 2 69
git fat pull happens nothing in centos 6.3 python 2.6.6 33 194
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now