简体   繁体   English

在shell脚本中运行ssh命令后如何在本地运行命令?

[英]How can I run commands locally after running ssh commands in a shell script?

I'm trying to write a shell script on Ubuntu 16.04 that will execute a command on another machine remotely, then execute more commands locally. 我正在尝试在Ubuntu 16.04上编写一个shell脚本,它将远程执行另一台机器上的命令,然后在本地执行更多命令。 I've tried this and it doesnt work 我试过这个并没有用

#!/bin/bash

ssh username@10.200.31.131 'pkill iperf'
ssh -f username@10.200.31.131 'iperf -s'

iperf -c 10.150.91.175 >iperflog.txt

It will execute the first 2 commands on the remote server but I think it is also trying to execute the last command on the remote server as well and I want to execute the last one on the local server. 它将在远程服务器上执行前2个命令,但我认为它也试图在远程服务器上执行最后一个命令,我想在本地服务器上执行最后一个命令。 How can I do this? 我怎样才能做到这一点? Thanks 谢谢

Perhaps your command stay Logged In! 也许你的命令保持登录状态!

Try to add a ; /bin/bash 尝试添加一个; /bin/bash ; /bin/bash to the end of your command line on the remote side ; /bin/bash到远程端命令行的末尾

ssh username@10.200.31.131 'pkill iperf; /bin/bash -i'

i hope help you 我希望能帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM