Solved

Help with Shell script

Posted on 2011-03-23
8
466 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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

617 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