0

我已经创建了一个这样的 shell 脚本,但是在 grant 命令中出现语法错误。请问有人可以帮我吗?

ssh -t qbadmin@10.3.2.0 '
 su root -c "
   echo \"Give db name :\";
   read db_name;
   echo \"Give password :\";
   read db_pass;
   host=localhost;
   sql1=\"create database \$db_name;\";
   sql2=\"grant all on \${db_name}.* to \${db_name}@\${host} identified by \"\${db_pass}\";\";
   sql3=\"\${sql1}\${sql2}\";
   echo \"==============\";
   mysql -u root -p -e \"\${sql3}\";
 ";
'
4

1 回答 1

0

我找到了解决方案。

通过在授权命令中放置"\\\""之前和之后,我解决了这个问题。\${db_pass}grant 命令运行良好,没有任何语法错误!

感谢大家的支持。

ssh -t qbadmin@10.3.2.0 '
 su root -c "
   echo \"Give db name :\";
   read db_name;
   echo \"Give password :\";
   read db_pass;
   host=localhost;
   sql1=\"create database \$db_name;\";
   sql2=\"grant all on \${db_name}.* to \${db_name}@\${host} identified by "\\\""\${db_pass}"\\\"";\";
   sql3=\"\${sql1}\${sql2}\";
   echo \"==============\";
   mysql -u root -p -e \"\${sql3}\";
 ";
'
于 2013-03-08T03:17:38.050 回答