LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   save info in dated files (https://www.linuxquestions.org/questions/linux-newbie-8/save-info-in-dated-files-496951/)

va1damar 10-30-2006 11:44 AM

save info in dated files
 
I've got cron running a little script that dumps a mysql table into a file. I would like to append a timestamp to the filename so that files do not overwrite each other. Is there a simple way to do that?

Code:

#!/bin/sh
/usr/local/mysql/bin/mysqldump -uuser -pnone --opt test weight --socket=/var/lib/mysql/mysql.sock --add-drop-table > test_table_dump.sql


b0uncer 10-30-2006 11:50 AM

Yes there is. Like this (quoting your own codepiece):
Code:

#!/bin/sh
datevar=$(date +"%F")
/usr/local/mysql/bin/mysqldump -uuser -pnone --opt test weight --socket=/var/lib/mysql/mysql.sock --add-drop-table > "test_table_dump_$datevar.sql"

I'm on XP machine now so can't test that but it ought to work. You might want to test with an empty text file first, to make sure it works, but that's the idea. For more information and fancy examples, take a look at linuxcommand.org, it's a good site and probably has an example there that does the above, takes a date and makes a variable out of it.


All times are GMT -5. The time now is 12:15 AM.