I wrote a script and I keep getting the following errors. access denied for user ‘zul’@’localhost (using password:yes) when trying to connect
proj: 43: [d: not found
proj: 43: [d: not found
It’s not reading the input d nor is it connecting to MySQL. Any Ideas?
Here is my Script:
#!/bin/bash
tstamp=$(date +$s)
#Dump or Update
if [ -z "$1" ]; then
echo -n "What do you want to do? [D]ump or [U]pdate: "
read parm
else
parm=$1
fi
#Database Name
if [ -z "$2" ]; then
echo -n "What database are you using?"
read dbname
else
dbname=$2
fi
#Database User
if [ -z "$3" ]; then
echo -n "What database user are you using?"
read dbuser
else
dbuser=$3
fi
#Database Password
if [ -z "$4" ]; then
echo -n "What password are you using?"
read dbpass
else
dbpass=$4
fi
#Checks if the directory exists
if test ! -d "/home/zul/sql/backup"; then
mkdir /home/zul/sql
mkdir /home/zul/sql/backup
fi
mysqldump $dbuser -p$dbpass $dbname > /home/zul/sql/backup/$tstamp.$dbname.sql
if [$parm = d ]; then
mysqldump $dbuser -p$dbpass $dbname > /home/zul/sql/backup/$dbname.sql
elif [$parm = u ]; then
mysqldump $dbuser -p$dbpass $dbname < /home/zul/sql/backup/$dbname.sql
else
echo " d or u option only! (lower case)"
fi
I guess there is a space missing in your if-else test:
Should be
[ test ]and not[test ]