![使用脚本运行时,日期命令在远程服务器中不起作用](https://linux22.com/image/109165/%E4%BD%BF%E7%94%A8%E8%84%9A%E6%9C%AC%E8%BF%90%E8%A1%8C%E6%97%B6%EF%BC%8C%E6%97%A5%E6%9C%9F%E5%91%BD%E4%BB%A4%E5%9C%A8%E8%BF%9C%E7%A8%8B%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%AD%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我正在从远程服务器的脚本运行以下命令,但出现错误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'