我有一段bash脚本如下,将远程机器上的数据库下载到本地进行使用:
#!/bin/bash
sftp user@11x.1xx.1x.2xx<<EOF
get /var/www/app/db/app.db /home/user/db_bak/
quit
EOF
mv /home/user/db_bak/app.db /var/www/app/db/
echo "done"
问题是文件下载完成,但是mv /home/user/db.bak/app.db /var/www/app/db/
和echo "done"
并未执行,这是为什么呢?刚接触,goole了半天也没有结果,求大神指点。
The path to save SFTP to local:
/home/user/db_bak/
The local file path you gave the mv program:
/home/user/db.bak/
Compare the differences between the two paths above. Give mv an incorrect local path and of course it won't move you.
I have never used sftp in a shell script. I don’t know if the execution of sftp will also give a signal to the shell to end, causing the following command to no longer be executed.
A personal suggestion: Why not use the relatively more secure and stable ssh (scp)? You don't have access to the server? If you have permission, it is recommended to use scp. This way you can save a few lines of commands