perl - 有没有办法远程到不同的机器,并在那里连续运行多个命令(使用 perl)?

标签 perl ssh remote-server

我有一个 Perl 脚本。我想远程到不同的主机,并在那里运行多个命令(不是 5,10 个而是 100-150 个命令)。就像,

Script1.pl(本地计算机上的脚本)的算法:

ssh machine10
// Then execute command1 on machine10
// Then execute command2 on machine10
// Then execute command3 on machine10
.
.
.
// Then execute command100 on machine10, and so on

Then exit, from the remote host.
Then, run the commands on the local machine.

如何实现?

我是 Perl 新手,浏览互联网后,我看到系统命令可以帮助 [system (ssh remote_host "command1; command2;..")],但是这个系统命令似乎不可行,因为 100-150要运行的命令不能这样编写。

有人可以帮忙吗? 有没有办法像我们打开一个 SSH 服务器,运行多个命令,然后关闭它?我实际上正在寻找这种类型的技术。

谢谢!

最佳答案

一种选择可能是将命令列表写入脚本文件(采用适合您的远程系统的任何格式 - bash、PowerShell 等)。然后,您可以使用 scp 将脚本复制到远程服务器,并使用 ssh 远程运行脚本。

关于perl - 有没有办法远程到不同的机器,并在那里连续运行多个命令(使用 perl)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70285870/

相关文章:

perl - 如何可视化/美化打印 HTML DOM 树?

javascript - 与 node.js 的 ssh 持久 session

shell - 我可以自动进行ssh连接吗? ssh user@server.company.com

Linux scp 命令不适用于指定端口

c# - 从 C# 远程 MS Sql 服务器备份和恢复

perl - 如何根据安装位置 "use lib"找到适当的目录?

linux - 在 perl 脚本中混合 vboxmanage 和 bash 命令

java - 如何调用 BSTR* 的 OleAutomation 对象方法?

ssh - 通过两个 ssh 跃点隧道 VNC

windows - 修改所有传出数据包的 TCP/IP header 中的目标端口