
リモートサーバーのスクリプトから以下のコマンドを実行していますが、エラーが発生します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 ....\" と書くと、文字列が引用符で囲まれず、引用符 1 文字だけが引用符で囲まれます。
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'