我有一个 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/