[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

Help with Shell script

I have the following shell script to produce a backup of my database run on a cron job every 2 days.

How can I put the date in this format mm_dd_yyyy in the output filename?
mysqldump -uadmin -ppwd inve_db --all --add-drop-table -Q | gzip > "/home/backup/mysqlbu_inve_db.sql.gz" 2>>"/home/backup/logs/Errorlog.txt"

Open in new window


0
Eddie Shipman
Asked:
Eddie Shipman
1 Solution
 
simon3270Commented:
> "/home/backup/mysqlbu_inve_db.sql.$(DATE '+%M_%D_%y").gz"
0
 
simon3270Commented:
Oops, caps-lock invert when I pasted this!

should be:
   > "/home/backup/mysqlbu_inve_db.sql.$(date '+%m_%d_%Y").gz"
0
 
simon3270Commented:
Not sure what's happening tody.  one more time, with feeling:

   > "/home/backup/mysqlbu_inve_db.sql.$(date '+%m_%d_%Y').gz"

(wrong quote at the end of the date format)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Eddie ShipmanAll-around developerAuthor Commented:
Will try it out later today.
0
 
pilson66Commented:
tstamp=$(date '+%m_%d_%Y'); mysqldump -uadmin -ppwd inve_db --all --add-drop-table -Q | gzip > "/home/backup/mysqlbu_inve_db-${tstamp}.sql.gz" 2>>"/home/backup/logs/Errorlog.txt"

Open in new window

0
 
Eddie ShipmanAll-around developerAuthor Commented:
Worked perfectly. Had a problem with another script called right after it but this part worked correctly.
0
 
TintinCommented:
I would highly recommend that you don't use ambiguous date formats.

Best to use YYYY_MM_DD

0
 
simon3270Commented:
with the added benefit that files are sorted in date order automatically
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now