Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with Shell script

Posted on 2011-03-23
8
Medium Priority
?
474 Views
Last Modified: 2012-05-11
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
Comment
Question by:EddieShipman
8 Comments
 
LVL 20

Expert Comment

by:simon3270
ID: 35198455
> "/home/backup/mysqlbu_inve_db.sql.$(DATE '+%M_%D_%y").gz"
0
 
LVL 20

Expert Comment

by:simon3270
ID: 35198464
Oops, caps-lock invert when I pasted this!

should be:
   > "/home/backup/mysqlbu_inve_db.sql.$(date '+%m_%d_%Y").gz"
0
 
LVL 20

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 35198484
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Author Comment

by:EddieShipman
ID: 35198900
Will try it out later today.
0
 
LVL 8

Expert Comment

by:pilson66
ID: 35199719
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
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 35201367
Worked perfectly. Had a problem with another script called right after it but this part worked correctly.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 35203732
I would highly recommend that you don't use ambiguous date formats.

Best to use YYYY_MM_DD

0
 
LVL 20

Expert Comment

by:simon3270
ID: 35213467
with the added benefit that files are sorted in date order automatically
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question