我的腳本被設計用來遍歷環境,點擊數據庫並檢查是否有任何名/姓組合具有關聯的用戶ID。我不知道爲什麼我得到下面列出的錯誤。使用like和%的SQL錯誤
#/bin/bash
#specify user to search for *******DO NOT PUT SPACE, ie. jaylefler
echo "Please enter user first name: "
read first_name
echo "Please enter user last name: "
read last_name
echo "Please enter LDAP User ID: "
read ldapuser
echo "Please enter LDAP password: "
stty -echo
read ldappw
stty echo
#logs to write output to
log="ui_${username}_access.log"
finallog="${username}_ui_access.txt"
#create file if not exist, else null it
[[ -f ${log} ]] && cat /dev/null > ${log} || touch ${log}
[[ -f ${finallog} ]] && cat /dev/null > ${finallog} || touch ${log}
#log it all
{
echo "environment"
sshpass -p $ldappw ssh [email protected] 'mysql -h host -u user - ppassword database -e \
"select user_id from users where first like "%'${first_name}'%" and last like "%'${last_name}'%";"'
} > $log
當我執行該腳本,我收到以下錯誤:
Please enter user first name:
jay
Please enter user last name:
lefler
Please enter LDAP User ID:
jlefler
Please enter LDAP password:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%jay% and last like %lefler%' at line 1
[email protected]:~/Desktop$
你沒有圍繞'jay''和''lefler''單引號 – paqogomez 2015-02-05 17:09:02