how to create file.txt and add current date in file content

Hey guy,

how to make bash script to create foo.txt file and add current date into file content and that file always append.

example: today the script run and add today date into content foo.txt

and tomorrow the script will run and add tomorrow date in content foo.txt without remove today date.

thanks
boly

You can just echo the date and append it to a file, if the file does not exist, then it is created.

-bash-3.2$ echo `date` >> dates.txt
-bash-3.2$ echo `date -d '+1 days'` >> dates.txt
-bash-3.2$ echo `date -d '+2 days'` >> dates.txt
-bash-3.2$ echo `date -d '+3 days'` >> dates.txt
-bash-3.2$ echo `date -d '+4 days'` >> dates.txt
-bash-3.2$ echo `date -d '+5 days'` >> dates.txt
-bash-3.2$ echo `date -d '+6 days'` >> dates.txt
-bash-3.2$ echo `date -d '+7 days'` >> dates.txt
-bash-3.2$ cat dates.txt
Thu Jun 18 04:27:24 CDT 2009
Fri Jun 19 04:27:36 CDT 2009
Sat Jun 20 04:27:49 CDT 2009
Sun Jun 21 04:27:52 CDT 2009
Mon Jun 22 04:27:55 CDT 2009
Tue Jun 23 04:27:58 CDT 2009
Wed Jun 24 04:28:00 CDT 2009
Thu Jun 25 04:28:04 CDT 2009

what have u tried...

Duplicated and answered : http://www.unix.com/shell-programming-scripting/112431-how-make-log-file-extract-time.html?highlight=script