0

I have the following code:

mysqldump -u root -h localhost -ppassword --all-databases > work.sql

I want the name of the sql file to be dependent on a variable.

My complete program is as follows:

#!/bin/bash
mysqldump -u root -h localhost -ppassword --all-databases > backup$time.sql
megaput --path /Root/Website/SQL/ backup$time.sql
rm backup$time.sql

I want to be able to replace $time with the current time and date when this file was ran. Is this possible, if so how?

Rixwaan
  • 45
  • 6
  • Just adapt the `date` format string to whatever you need. For something like `HHMMSS`, it'd be `+%H%M%S`. – Benjamin W. Dec 22 '17 at 18:20
  • Or https://stackoverflow.com/questions/12773853/append-the-time-stamp-to-a-file-name-in-ubuntu – Benjamin W. Dec 22 '17 at 18:21
  • `...--all-databases > "backup on $(date +%Y-%m-%d\ at\ %H.%M).sql"` will output to a file that’s named like *backup on 2017-12-23 at 19.29.sql* – CJK Dec 23 '17 at 19:34

0 Answers0