
jeffersno1
Novice
Aug 12, 2014, 5:08 PM
Post #1 of 5
(13788 views)
|
change syntax for variables within wget
|
Can't Post
|
|
hi guys, I need some help with some syntax. So what i'm looking to do is run a cron task every night and in the script will be a bunch of commands to get files off a server and store them for other monitoring systems. I need to put epoc time in the filename that im downloading and this is where i'm getting stuck... in brief this is the line with the issue:
my $response = $ua->get('http://webserver/graphs/epdf/download.pl?rrd=01_allpass_kt&time1=$epoc&time2=$yest'); ### THIS DOESNT WORK - trouble setting variables here :( #my $response = $ua->get('http://webserver/graphs/epdf/download.pl?rrd=01_allpass_kt&time1=1407681301&time2=1407854101'); ##### THIS WORKS Here is my script so far: please be aware i've copied some of this off the internet
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Cookies; use POSIX; use File::Basename; my $epoc = time(); ## set time to now print "time now $epoc\n"; ## check above works my $yest = ($epoc - 86400); ## set time to 24hrs earlier print "yest - $yest\n"; ## check above works sub main { # Create the fake browser (user agent). my $ua = LWP::UserAgent->new(); # Accept cookies. You don't need to supply # any options to new() here, but just for # kicks we'll save the cookies to a file. my $cookies = HTTP::Cookies->new( file => "cookies.txt", autosave => 1, ); $ua->cookie_jar($cookies); # Pretend to be Internet Explorer. $ua->agent("Windows IE 7"); # or maybe .... $ua->agent("Mozilla/8.0"); # Get some HTML. my $response = $ua->get('http://webserver/graphs/epdf/download.pl?rrd=01_allpass_kt&time1=$epoc&time2=$yest'); ### THIS DOESNT WORK - trouble setting variables here :( #my $response = $ua->get('http://webserver/graphs/epdf/download.pl?rrd=01_allpass_kt&time1=1407681301&time2=1407854101'); ##### THIS WORKS unless($response->is_success) { print "Error: " . $response->status_line; } # Let's save the output. my $save = "/tmp/allpass.xls"; unless(open SAVE, '>' . $save) { die "nCannot create save file '$save'n"; } # Without this line, we may get a # 'wide characters in print' warning. binmode(SAVE, ":utf8"); print SAVE $response->decoded_content; close SAVE; print "Saved " . length($response->decoded_content) . " bytes of data to '$save'."; } main(); Any help is greatly appreciated. Many thanks Jeffers
(This post was edited by jeffersno1 on Aug 18, 2014, 9:47 AM)
|