PHP in the Command Line
By Robert Plank2005-05-25
Here today, gone tomorrow
But say we wanted that text file to be named according to the current date. You already have the pieces to figure all that out, if you think about it. Type: date --help to get a listing of all the possible ways to represent the date. The ones you want to represent the year, month and day are %Y, %m, and %d (capitalization *is* important here).
This is what you want: echo `date +%Y%m%d.html`
Running this today, January 8th, 2004, results in: 20040108.html
I've just echoed this year, followed by this month and this day, with an ".html" at the end. This will be our output file.
Now, to pipe it: echo "hey" > `date +%Y%m%d.html`
If this sort of thing were to run every day, it would save "hey" to a file called 20040108.html today, and tomorrow to a file called 20040109.html, then 20040110.html, and so on.
The easy part now, is figuring out what you want archived. I use wget, which takes an option to store the output file, so we don't need to use piping. Here's an example of how to use wget to save the page "http://www.google.com"; to a file representing today's date:
wget http://www.google.com --output-document=`date +%Y%m%d.html`
Tutorial Pages:
» Listen closely and you'll hear the ocean
» Pipe down over there
» Here today, gone tomorrow
» Put it together
» Arguments (not the shouting kind)
