1

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?

3 Answers 3

3

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 
Sign up to request clarification or add additional context in comments.

Comments

3

e.g.

date +%Y%m%d-%H%M 

Comments

3

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.