Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在sql字符串中使用bash参数的脚本问题_Mysql_Linux_Bash - Fatal编程技术网

Mysql 在sql字符串中使用bash参数的脚本问题

Mysql 在sql字符串中使用bash参数的脚本问题,mysql,linux,bash,Mysql,Linux,Bash,我在bash脚本中运行sql时遇到一些问题。有人能建议需要更改哪些语法吗 { echo "listing" sshpass -p 'XXXXXX' ssh jlefler@12.345.67.890 'mysql -h host -u user -pXXXXXX database -e "select user_id from users where concat(FIRST,LAST) like '%${username}%';"' } > $log 以下是我收到的错误消息: ERRO

我在bash脚本中运行sql时遇到一些问题。有人能建议需要更改哪些语法吗

{
echo "listing"
sshpass -p 'XXXXXX' ssh jlefler@12.345.67.890 'mysql -h host -u user -pXXXXXX database -e "select user_id from users where concat(FIRST,LAST) like '%${username}%';"'
} > $log
以下是我收到的错误消息:

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 '%jaylefler%' at line 1
当我按照以下建议更改脚本时,我收到以下错误:

bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `mysql -h host-u user -pxxxxxxx database -e select user_id    from users where concat(FIRST,LAST) like '%name_here%';'
我最初的“工作部分”如下:

echo "environment"
sshpass -p $ldappw ssh $ldapuser@54.123.456.123  'mysql -h host -u user -ppassword database -e "select concat(FIRST,LAST) from users;"' | (grep -i ${username} || echo "NO USER IDENTIFIED")

我只是想修改它,这样我就可以打印出找到的用户ID,而不是每次找到名字和姓氏组合时都打印出用户名。

你已经准备好接受SQL注入攻击了

然而,sql需要在模式周围加上单引号。另外,您不需要引用发送给ssh的命令。因此:

sshpass -p 'XXXXXX' ssh jlefler@12.345.67.890 mysql -h host -u user -pXXXXXX database -e "select user_id from users where concat(FIRST,LAST) like '%${username}%';"
# ............................................^ remove quote ........................................................................................ remove quote ^
“不起作用”作为错误描述比无用更糟糕。发生了什么事?