在远程计算机上运行bash脚本的一部分
我需要在本地运行一些命令,然后在远程机器上运行一些命令,所有这些都使用一个本地bash脚本 为了简单起见,只需说我想执行以下操作并在本地桌面计算机上执行即可在远程计算机上运行bash脚本的一部分,bash,ssh,Bash,Ssh,我需要在本地运行一些命令,然后在远程机器上运行一些命令,所有这些都使用一个本地bash脚本 为了简单起见,只需说我想执行以下操作并在本地桌面计算机上执行即可 #!/bin/bash #upload some files to a remote machine cd /tmp ./upload-files.sh #run commands on remote machine ssh myuser:mypass@somewhere.com cd /tmp/uploads <--- t
#!/bin/bash
#upload some files to a remote machine
cd /tmp
./upload-files.sh
#run commands on remote machine
ssh myuser:mypass@somewhere.com
cd /tmp/uploads <--- these commands don't run in the ssh connection
./process-uploads.sh
exit
#run command locally again.
cd -
echo 'complete!'
#/bin/bash
#将一些文件上载到远程计算机
cd/tmp
./upload-files.sh
#在远程计算机上运行命令
ssh myuser:mypass@somewhere.com
cd/tmp/uploads您可以使用ssh
命令:
#!/bin/bash
#upload some files to a remote machine
cd /tmp
./upload-files.sh
#run commands on remote machine
ssh -t -t myuser:mypass@somewhere.com<<EOF
cd /tmp/uploads
./process-uploads.sh
exit
EOF
#run command locally again.
cd -
echo 'complete!'
#/bin/bash
#将一些文件上载到远程计算机
cd/tmp
./upload-files.sh
#在远程计算机上运行命令
ssh-t-t我的用户:mypass@somewhere.com如果只想运行一个命令:
ssh myuser:mypass@somewhere.com 'cd /tmp/uploads; ./process-uploads.sh'
我是否需要双-t-t
?对于单-t
,我得到一个警告,因为stdin不是终端,所以不会分配伪终端。