Topic: getting date with shellscript

I want to cron a tiny script to backup my sqlite database.

it should copy the file 'db' to the file 'db20070327'.

Any hint on how to get the date and concatenate strings in shellscript?

I could easily do it with other programming language, but i want to try shellscript. thanks

Re: getting date with shellscript

Under bash, I use this:

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

3 (edited by pedrotuga 2007-03-29 19:55)

Re: getting date with shellscript

mmm so...

piece2='date "+%Y-%m-%d"'
piece1='mydb'
filename="${piece1}${piece2}"
cp mydb filename

i am a still a bit confusing with the way the string variables are handled ( noob )

would that do it?

Re: getting date with shellscript

Why bother with variables?

cp mydb mydb_`date "+%Y-%m-%d"`.sql.gz;

should work fine.

Re: getting date with shellscript

Jérémie wrote:

Why bother with variables?

cp mydb mydb_`date "+%Y-%m-%d"`.sql.gz;

should work fine.

don't mind me... noob codding, lol.

Allow me a question... why name the file .gz if it's not gziped?

Thanks for the script

Re: getting date with shellscript

as much as I love bash, I could never remember the crappy syntax to script in it.  my shell scripts always start out w/ #!/bin/csh tongue  not that I could use it as a shell, just easier to remember syntactically.