Register
It is currently Sun Dec 21, 2014 5:36 am

Simple loop. Error expecting "do"...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Apr 07, 2014 5:57 am   

Joined: Mon Apr 07, 2014 5:48 am
Posts: 2
Hello,

With this simple for loop, I get an error message. Expecting "do".

Can someone please help me out with this? What am I doing wrong?

Thanks a lot.

Andrew

#! /bin/sh
DATE=`date '+%Y.%m.%d'`
FOLDER=/home/backups
MYSQLUSER=admin
MYSQLPASSWD=``
DATABASES=`mysql -u $MYSQLUSER -e 'SHOW DATABASES' | sed '1,2d'`
for i in $DATABASES ;
do
echo "Dumping $i... database" in $FOLDER
mysqldump -u $MYSQLUSER $i > $FOLDER/$i.$DATE.sql
done
echo "`echo $DATABASES | wc -w` Databases were backed up in $FOLDER"


Top
 Profile  
 PostPosted: Thu Aug 21, 2014 1:03 pm   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
quote your variables?

Some VARs I use and how I quote them in bash:
Code:
NASMOUNT=/c9backups
HOSTNAME="c9wiki"
WORKDIR=/tmp/"$HOSTNAME"
TARDATE=$(date '+%m-%d-%Y')

# We only keep 1 file on this host
rm "$NASMOUNT"/$HOSTNAME/*.tar.gz

mysqldump -u<user> -p<pass> <dbname> > "$WORKDIR"/$HOSTNAME-wiki_db.sql
tar -pczf $NASMOUNT/$HOSTNAME/c9wiki_$(date +%F).tar.gz "$WORKDIR"/$HOSTNAME-wiki_db.sql /var/www/*
rm "$WORKDIR"/$HOSTNAME-wiki_db.sql


Hope that helps.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP