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).txt
but I receive an error that the command is ambiguous.
Thanks for your help!
Sorin
The
datecommand can be given a format to determine exactly what form it generates dates in. It looks as if you want$(date +%Y%m%d-%H%M%S).txt. With this format, the output ofdateshould be free of spaces, parentheses, etc., which might otherwise confuse the shell or thelynxcommand.See http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/date.1.html for documentation of the
datecommand and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strftime.3.html for documentation of the format string, which is the same as for thestrftimefunction in the standard library.