Solved

Easy Bash scripting question

Posted on 2004-08-31
4
263 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 250 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

Stressed Out?

Watch some penguins on the livecam!

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

631 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