使用脚本运行时,日期命令在远程服务器中不起作用

使用脚本运行时,日期命令在远程服务器中不起作用

我正在从远程服务器的脚本运行以下命令,但出现错误No such file or directory

ssh -t -t [email protected] \"sudo mysql nss_mysql < /home/user/scripts/Db_nss_mysql-`date +%Y-%m-%d`.sql && /bin/bash /home/user/scripts/jenkin-soft.sh\"

我运行起来bash jenkin-soft.sh,完整的错误是:

jenkin-soft.sh: line 36: /home/user/scripts/Db_nss_mysql-`date +%Y-%m-%d`.sql: No such file or directory. 

我尝试了以下命令,它们工作正常::

givinv@ser1:~/scripts$ ssh -t -t [email protected] "sudo mysql"
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 66

mysql> Bye
Connection to xx.xx.xx.xx closed.
givinv@ser1:~/scripts$ ssh -t -t  [email protected] "sudo ls /home/user/scripts/Db_nss_mysql-`date +%Y-%m-%d`.sql"
/home/user/scripts/Db_nss_mysql-2017-04-07.sql
Connection to xx.xx.xx.xx closed.
givinv@ser1:~/scripts$ 

我做错了什么?

答案1

你的引用在这里有问题,或者更确切地说是缺乏它。因为当你写: \"sudo ....\" 时,它不会引用你的字符串,而是引用一个引号 char "

ssh -t -t [email protected] 'sudo mysql nss_mysql < /home/user/scripts/Db_nss_mysql-`date +%Y-%m-%d`.sql && /bin/bash /home/user/scripts/jenkin-soft.sh'

相关内容