我目前有一个如下所示的脚本:
sql="SELECT id FROM user
WHERE (email LIKE '%a@b.com'
OR email LIKE '%c@d.com'
OR email LIKE '%f@g.com' );"
read -a ids < <(ssh localhost "mysql test -e \"$sql\"")
但它没有正确执行。使用set -x
时,输出如下所示:
+ read -a usu_ids
++ ssh localhost 'mysql test -e " SELECT' id FROM user WHERE '(usu_email' LIKE ''\''%a@b.com'\''' OR email LIKE ''\''%c@d.com'\''' OR email LIKE ''\''%f@g.com'\''' '); "'
它给出了一个虚假的价值。 有什么建议吗?
由于
答案 0 :(得分:0)
Option 1:
以下是一个示例,您可以调整它以满足您的需求:
$ ssh user@hostname <<END
> cd temp_files
> ls -lrt
> #Run any commands on the remote host here
> END
total 4
drwxr-xr-x 2 test test 4096 May 27 14:18 cron_log
Option 2 :
您可以将命令放在本地脚本中的远程主机上,并使用ssh运行它。下面给出一个例子:
$ cat SO.sh
cd ~/temp_files
ls -lrt | awk '{print $9}'
$
$ myVar=`ssh user@remotehost 'bash -s' < SO.sh`
$
$ echo ${myVar}
cron_log
答案 1 :(得分:0)
我认为你应该将mysql数据库名称放在mysql命令的末尾:
read -a ids < <(ssh localhost "mysql -e \"$sql\" test")