tags:

views:

44

answers:

3

I'm trying to do something like this:

mysqldump --user c1bt3 --password=blah c1bt3 > c1bt{date}.sql

where date is replaced with the current date, i.e. c1bt5-11-10.sql, and I'm trying to do it from a linux shell script.

Any ideas how I can do this?

+2  A: 

e.g.

date +%Y%m%d-%H%M
ThiefMaster
+2  A: 

You can either use the date command with your favourite formating

DATE=$(date)
mysqldump --user c1bt3 --password=blah c1bt3 > c1bt${DATE}.sql

or use the date formating capailities of your shell, which can vary a bit.

This is ZSH:

$ print -P "%D{%H:%M:%S}"
22:30:23

Same usage...

DATE=$(print -P "%D{%H:%M:%S}")
mysqldump --user c1bt3 --password=blah c1bt3  > c1bt${DATE}.sql
LukeN
+2  A: 

A fast way is this, which will give the date as yyy-mm-dd:

mysqldump --user c1bt3 --password=blah c1bt3 > c1bt$(date -I).sql

If the ordering of the date parts is important, try this:

mysqldump --user c1bt3 --password=blah c1bt3 > c1bt$(date +%d-%m-%y).sql

(I'm a big fan of Bash and am not very fluent in other shells, so my answer should be treated as Bash-only)

Emil Vikström