I have set up a cron task and I want to save the output to a file. The file should have the name based on the time at which the cron was executed (eg.: 20110317-113051.txt).
My actual cron command is as follows:
lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txt
I want the textfile
to be replaced by some sort of unique time stamp.
I've tried
lynx -dump http://somesite/script.php > $(date).txtbut I receive an error that the command is ambiguous.
Thanks for your help!
Sorin
You need to quote the file name, since date by default will have special characters in it:
lynx -dump http://somesite/script.php > "$(date).txt"
As @Gareth says though, you should specify a format string for date, so that you get a more readable/manageable file name, e.g.
lynx -dump http://somesite/script.php > "$(date +%Y%m%d-%H%M%S).txt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With