Solved

Help with Shell script

Posted on 2011-03-23
8
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 19

Expert Comment

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

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 19

Accepted Solution

by:
simon3270 earned 500 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
Industry Leaders: 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 19

Expert Comment

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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Postfix issues with spam/auth attempts under NAT 9 136
cannot rename datastore 3 98
Why  my code (program) build with old compiler? 11 113
Linux FTP Error 5 46
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

733 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