Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Easy Bash scripting question

Posted on 2004-08-31
4
Medium Priority
?
268 Views
Last Modified: 2010-04-21
I'm a programmer, but not familar with Linux scripting.

I have a script that stops MySQL, zips up the database files, and then restarts MySQL.  The tar files are named mysql-YYYYMMDD.tar.gz, but I need to run the process more than once a day.  So that I would end up with.

mysql-YYYYMMDD-001.tar.gz
mysql-YYYYMMDD-002.tar.gz

I'm guessing I'm going to have check to see if file ...001 exists then ...002 in a loop, but I'm having a hard time getting it to work.
0
Comment
Question by:steve918
[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
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 1000 total points
ID: 11944003
#!/bin/bash

tar_file_name=$(date +mysql-%Y%m%d)
i=1
while [ -f ${tar_file_name}$i ]; do
    i=$(expr $i + 1)
done

next_full_tarfile=${tar_file_name}-${i}.tar

# where blagh here are the files to be tarred...
tar cf $next_full_tarfile blagh
gzip -9 $next_full_tarfile
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11944038
appologies, the 5th line (while...) should read as follows:

while [ -f ${tar_file_name}-${i}.tar ]; do

Cheers,
C.
0
 
LVL 3

Author Comment

by:steve918
ID: 11946232
I had to change the while to include the .gz like so

while [ -f ${tar_file_name}-${i}.tar.gz ]; do

Then everything worked great.  THANKS.
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11950187
d'oh, forgot that too... thanks for the points.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

705 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