PDA

View Full Version : Date Variable to Filename



theaudioforum
04-28-2004, 09:55 PM
I would like to append the date to the filename of a MySQL backup that I am performing via a shell script.

Simplified script:
#!/bin/sh
databases="mysql theaudioforum"
today='date +%Y-%m-%d'
for database in $databases
do
mysqldump -u root --opt $database > /backups/${database}-$today.sql
done
####

I end up with files named like this: mysql-date +%Y-%m-%d.sql

How can I correct the script so that I end up with a file named like: mysql-2004-4-29.sql ?

Thanks!!

dpfaigin
04-29-2004, 04:06 AM
I think, in your

today = 'date...'

example, you need to use grave accents, not single quotes, i.e.,

today = `date ...`

Daniel

theaudioforum
04-29-2004, 09:45 AM
Thanks! That took care of it.