[thelist] Cron/Ping?

John Garvin jpg at twinight.org
Thu Mar 13 20:03:07 CST 2003


On Fri, Mar 14, 2003 at 10:45:45AM +0900, Christian Anderson wrote:
> That sounds like a good plan.  The other suggestions are good as well, but I
> am developing a mobile application so therefore there is no PC at my
> disposal that can refresh a page every minute.
> 
> Soooooooo, I know nothing about perl or how to set up a cron job... are
> there any pre-made scripts available?
> 
> Chris
> 


This will work; change the url, of course.;
if you're going to run it via cron, put a # in front of the sleep line.

do a 'man crontab' on whatever machine you wind up using for the
proper syntax.



-- 
#!/path/to/perl   # <- change this, of course
#
#
# straight from perldoc.
use LWP::UserAgent;


my $url="http://www.google.com";

while(1) {
    my $ua = new LWP::UserAgent;
    $ua->agent("Mozilla/3.0 " . $ua->agent);

    my $req = new HTTP::Request GET =>"$url";
    $req->content_type('application/x-www-from-urlencoded');
    $req->content('match=www&errors=0');

    my $response = $ua->request($req);

    if ($response->is_success) {
        print $response->content;
    } else {
        print "unknown error--\n $! \n";
    }
    sleep 5;   # will grab every 5 seconds, change for a longer pause

}



More information about the thelist mailing list