我正在研究一个脚本,该脚本将用于从远程位置传输文件(使用rsync),然后对检索到的内容执行一些基本操作。
当我最初连接到远程位置(不运行rsync守护程序时,我只是使用rsync来检索文件)时,我被放置在非标准外壳中。为了进入bash shell,我需要输入“ run util bash”。有没有一种方法可以在rsync开始传输文件之前执行“ run util bash”?
如果有办法使用scp / ftp而不是rsync,我可以接受其他建议。
一种方法是从服务器而不是从客户端执行rsync。ssh反向隧道使我们能够从远程服务器临时访问本地计算机。
命令:
ssh -R 2222:localhost:22 remoteuser@remotemachine << EOF
# we are on the remote server.
# we can ssh back into the box running the ssh client via ${REMOTE_PORT}
run utils bash
rsync -e "ssh -p 2222" --args /path/to/remote/source remoteuser@localhost:/path/to/local/machine/dest
EOF
Run Code Online (Sandbox Code Playgroud)
将复杂命令传递给ssh的参考: 在bash中最简单的ssh和运行多个命令的方法是什么?