1.

Solve : bash custom variable?

Answer»

I have a bash script that backups database. What I WANT to do is save the FILE with its name and the current date. Here is my script.

#!bash/sh
#
MYDATETIME=;date +%Y-%m-%d

mysqldump -uroot -pdthscyth jobs > jobs_$MYDATETIME.sql


The PROBLEM is when saving the file the value of the variable is not saved. Instead of jobs_2010-12-29.sql the filename is jobs_.sql. Please help. Thanks and Happy New Year!.

I figure it out. Commands LIKE date should be inside a back quote (`) so instead of

mysqldump jobs > jobs_$MYDATETIME.sql

it should be...

mysqldump jobs > jobs_`date +%Y-%m-%d.sql`



Discussion

No Comment Found