Cron Job to grab a text file

software development

#1

I want to write a php program to grab a report that changes each day so I could save a copy in a DH directory for a permanent record. The url is :http://www.usbr.gov/pn/hydromet/yakima/yakstats.txt. I started writing a little php program to give the url to curl, then explode it on newline characters to an array, then write the array to a file and save to a directory with the file name derived from the current system date. But then I thought, hey it’s already just a text file. Do I need to get this complicated? Is there a way to just copy the text file from the original location to my directory? A shell script even?


#2

crontab + cURL + some Perl for the filename?


#3

Don’t even need Perl for that; A bash script can derive a filename to include the date, etc.


#4

you are obviously more grizzled than i! I don’t know bash scripting, though, so there’s a new thing to learn.


#5

Use lynx in a bash script to get the text file, then save it to a directory with filename + sys date string?


#6

You only need two lines:

wget http://www.usbr.gov/pn/hydromet/yakima/yakstats.txt
mv yakstats.txt "`date +%Y%m%d_%H`_takstats.txt"

Regards,
Omar


#7

Or, as a one-liner:


#8

Oh, yeah, wget! Thanks, guys.