The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed - searching for string and storing in variable melias Shell Programming and Scripting 4 04-12-2008 02:57 PM
Problem while storing sql query value in a variable krishna_gnv Shell Programming and Scripting 1 02-28-2008 07:37 AM
Storing the output into a variable ravi raj kumar UNIX for Dummies Questions & Answers 7 12-11-2006 09:14 AM
storing output of awk in variable mab_arif16 Shell Programming and Scripting 3 05-07-2006 06:15 PM
Storing values in variable matrixmadhan Shell Programming and Scripting 1 04-01-2005 01:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-26-2008
hoover90 hoover90 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
Storing a variable?

I'm writing a bash shell script to backup several mysql databases. This script will run on a daily basis and send a copy to a remote FTP repository. The filenames are in the format DATE.backup.sql. How do I store the DATE variable so I can delete/move/etc the file on the FTP server the next time the script runs?

Code:
#!/bin/bash

DATE=$(date +%d%b%y_%k.%M.%S)

cd /web/.hhome/mysql.backup/data
mysqldump -ubackup -ppassword --databases db1 db3 > $DATE.backup.sql

gzip -9 $DATE.backup.sql

crypt key < $DATE.backup.sql.gz > $DATE.backup.sql.enc.gz
rm -rf $DATE.backup.sql.gz

ftp -inv ftp.somehost.com<<ENDFTP
user hoover90 password
put $DATE.backup.sql.enc.gz
bye
ENDFTP
I can use pretty much any method, but it has to be done within this bash script.

Thanks!

Last edited by hoover90; 01-26-2008 at 07:19 PM..
  #2 (permalink)  
Old 01-26-2008
lucaswoods lucaswoods is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 9
At the top of the script:
read LASTDATE < .last_date

During the FTP session:
del $LASTDATE.backup.sql.enc.gz

After the FTP session:
echo $DATE > .last_date

Of course you will need some conditional logic there to deal with .last_date not existing... you could create the first .last_date file manually yourself. If you need help with that as well let us know.
  #3 (permalink)  
Old 01-26-2008
hoover90 hoover90 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
Alright, everything you suggested works except for writing $DATE to .last_date. From bash, I can use the same command format (replacing $DATE with $(date +%d%b%y_%k.%M.%S), or just echo "asdfqwer1234blahblah" > .last_date), but it will not write $DATE to .last_date when the script is executed.

Code:
#!/bin/bash

read LASTDATE < .last_date
DATE=$(date +%d%b%y_%k.%M.%S)

cd /web/.hhome/mysql.backup/data
mysqldump -ubackup -ppassword --databases db1 db2 db3 > $DATE.backup.sql

gzip -9 $DATE.backup.sql
crypt asdfqwer1234 < $DATE.backup.sql.gz > $DATE.backup.sql.enc.gz
rm -rf $DATE.backup.sql.gz

ftp -inv ftp.somehost.com<<ENDFTP
user hoover90 password
del $LASTDATE.backup.sql.enc.gz
put $DATE.backup.sql.enc.gz
bye
ENDFTP

echo $DATE > .last_date
  #4 (permalink)  
Old 01-26-2008
lucaswoods lucaswoods is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 9
That is because you are reading the .last_date from your current working directory, then changing to /web/.hhome/mysql.backup/data before writing out the variable.

I'm guessing if you check /web/.hhome/mysql.backup/data/.last_date it will be there.

I would move the "read LASTDATE < .last_date" to AFTER the cd /web/.hhome/mysql.backup/data.
  #5 (permalink)  
Old 01-26-2008
hoover90 hoover90 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
You guessed right! It works!

Thank you!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0