[英]When I run a bash script that ssh's into a remote server and run a command like wget it saves on the source not the destination server?
I have the following bash script 我有以下bash脚本
#!/bin/bash
ssh -o "StrictHostKeyChecking no" ubuntu@$1
cd /home/ubuntu
wget google.com
When I run it, ./test.sh
I am ssh'd into the remote server but the wget
command is not run unless I press ctrl+d and then the ssh session exits and the index.html
file is saved to /home/ubuntu
当我运行它时,。/ ./test.sh
我被ssh'到远程服务器中,但是除非我按ctrl + d ,否则wget
命令不会运行,然后ssh会话退出并且index.html
文件保存到/home/ubuntu
How can I change this bash script so that I can save the index.html
file on the remote server? 如何更改此bash脚本,以便可以将index.html
文件保存在远程服务器上?
只需在ssh
的命令行中指定要执行的命令即可:
ssh -o "StrictHostKeyChecking no" ubuntu@$1 'cd /home/ubuntu; wget google.com'
What your script does: 您的脚本的作用是:
What you want is to make a script on the remote host and execute it: 您想要在远程主机上创建一个脚本并执行它:
run.sh
#!/bin/sh
cd /home/ubuntu
wget google.com
And in the script on the local host: 并在本地主机上的脚本中:
ssh -o "StrictHostKeyChecking no" ubuntu@$1 run.sh
You have the concept of bash very wrong. 您对bash的概念非常错误。 Bash is not a way to create macros that do the typing for you. Bash不是创建为您进行键入的宏的方法。 Bash is a scripting language that will execute a series of commands on the local machine. Bash是一种脚本语言,它将在本地计算机上执行一系列命令。 This means that it is going to run an ssh command which connects to the remote host. 这意味着它将要运行一条连接到远程主机的ssh命令。 Once the ssh script is done executing, bash will execute the cd and then the wget. 一旦ssh脚本执行完毕,bash将执行cd,然后执行wget。
What you want to do is pass the commands to the remote ssh server. 您要做的是将命令传递到远程ssh服务器。
#!/bin/bash
ssh -o "StrictHostKeyChecking no" ubuntu@$1 "cd /home/ubuntu; wget google.com"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.