我如何可以自动通过SSH远程运行命令? [英] How can I automate running commands remotely over SSH?

查看:143
本文介绍了我如何可以自动通过SSH远程运行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一下周围类似的问题,但除此之外,运行一个命令或者用物品,如一些命令:

I've searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as:

ssh user@host -t sudo su -

但是,如果我基本上需要运行一个脚本(假设)15台服务器的一次。这是可行的在bash?在一个完美的世界,我需要避免安装应用程序,如果在所有可以拉动这一关。为了便于讨论,让我们只说我需要跨10个主机做到以下几点:

However, what if I essentially need to run a script on (let's say) 15 servers at once. Is this doable in bash? In a perfect world I need to avoid installing applications if at all possible to pull this off. For argument's sake, let's just say that I need to do the following across 10 hosts:


  1. 部署一个新的Tomcat容器

  2. 部署在容器中的应用程序,并将其配置

  3. 配置Apache虚拟主机

  4. 刷新阿帕奇

我有一个脚本,做了这一切,但是它依赖于我登录到所有服务器,从回购拉着一个脚本下来,然后运行它。如果这是不可行的在bash,你有什么建议的替代品?我需要一个更大的锤子,如Perl(Python的可能是preferred因为我可以保证Python是在所有箱子在RHEL环境,感谢百胜/ up2date的)?如果任何人都可以指向我任何有用的信息,这将会是很大的AP preciated,尤其是如果它在bash可行的。我会满足于Perl或Python的,但我只是不知道这些,以及(就这一工作)。谢谢!

I have a script that does all of that, but it relies on me logging into all the servers, pulling a script down from a repo, and then running it. If this isn't doable in bash, what alternatives do you suggest? Do I need a bigger hammer, such as Perl (Python might be preferred since I can guarantee Python is on all boxes in a RHEL environment thanks to yum/up2date)? If anyone can point to me to any useful information it'd be greatly appreciated, especially if it's doable in bash. I'll settle for Perl or Python, but I just don't know those as well (working on that). Thanks!

推荐答案

通常情况下,我只用期待的原始的Tcl版本。你只需要有在本地计算机上。如果我使用Perl程序里面,我做这与的Net :: SSH ::期待 。其他语言也有类似的期望的工具。

Often, I'll just use the original Tcl version of Expect. You only need to have that on the local machine. If I'm inside a program using Perl, I do this with Net::SSH::Expect. Other languages have similar "expect" tools.

这篇关于我如何可以自动通过SSH远程运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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