LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Linux Bash Date Characters (https://www.linuxquestions.org/questions/linux-software-2/linux-bash-date-characters-396057/)

matsko 12-23-2005 06:34 PM

Linux Bash Date Characters
 
I want to have a system where when I backup my mysql database. The script would save the filename according to its date.

so

mysql_backup_full-2005-23-12.sql
mysql_backup_full-2005-24-12.sql
mysql_backup_full-2005-25-12.sql

...and so on

but you see how the date of the file is different (because it is backed up on a certain day)

how would I make the name so that when the backup_mysql file is executed it would save the filename as today's date..


thanks

linmix 12-24-2005 05:23 AM

set a date variable in your script
date='date -y -d' (check out the flags you need, these are just a random example!!)

then write the outgoing filename like this:

mysql_backup_full-"$date".sql

DarkElf109 12-24-2005 06:00 AM

date=`date +%Y-%d-%m`

Put that somewhere in your script, and, as linmix said, use $date wherever you want the date, in your specified format, to show up.


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