我寫了一個腳本,並且不斷收到以下錯誤。嘗試連接備份MySQL數據庫的Bash腳本
凸出時:43:d:沒有找到
凸出:43:拒絕訪問用戶 'ZUL' @'本地主機(是使用密碼)[d:沒有找到
它不是讀取輸入d,也不是連接到MySQL。有任何想法嗎?
這裏是我的腳本:
#!/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
是不是th基本上只是構建一個命令行來調用mysqldump?我會質疑這種腳本的用處。這聽起來,至少對我來說,就像還有一件事情要維護,沒有多少好處。 – 2012-07-28 16:50:34
你試過用'bash -vx'運行你的腳本嗎?這有助於很多,並會讓你找到你的bug – 2012-07-29 08:03:38