BashScripts.org
http://bashscripts.org/forum/

Simple loop. Error expecting "do"...
http://bashscripts.org/forum/viewtopic.php?f=7&t=1807
Page 1 of 1

Author:  Roastbeef70 [ Mon Apr 07, 2014 5:57 am ]
Post subject:  Simple loop. Error expecting "do"...

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"

Author:  Habitual [ Thu Aug 21, 2014 1:03 pm ]
Post subject:  Re: Simple loop. Error expecting "do"...

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.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com