当我运行一个SSH到远程服务器的bash脚本并运行wget之类的命令时,它将保存在源服务器上而不是目标服务器上吗? [英] 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?

查看:37
本文介绍了当我运行一个SSH到远程服务器的bash脚本并运行wget之类的命令时,它将保存在源服务器上而不是目标服务器上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下bash脚本

#!/bin/bash
ssh -o "StrictHostKeyChecking no" ubuntu@$1
cd /home/ubuntu
wget google.com

当我运行它时, ./test.sh 我被ssh到远程服务器,但是 wget 命令不会运行,除非我按 ctrl+ d ,然后ssh会话退出,并将 index.html 文件保存到/home/ubuntu

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

如何更改此bash脚本,以便可以将 index.html 文件保存在远程服务器上?

How can I change this bash script so that I can save the index.html file on the remote server?

推荐答案

脚本的作用:

  • 打开与指定主机的交互式连接
  • 等待连接完成(这就是为什么必须按Ctrl-D的原因)
  • 在本地执行一些命令

您想要的是在远程主机上创建一个脚本并执行它:

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

这篇关于当我运行一个SSH到远程服务器的bash脚本并运行wget之类的命令时,它将保存在源服务器上而不是目标服务器上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆