
我正在從遠端伺服器的腳本運行以下命令,但出現錯誤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'