[英]Is there a way to remote to a different machine, and run multiple commands there in series (using perl)?
我有一个 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 服务器,运行多个命令,然后关闭它? 我实际上正在寻找这种类型的技术。
谢谢!
您可能会达到命令行长度的限制。
my @remote_cmds = ...;
open( my $pipe, "|-", "ssh", "machine10", "sh" );
for my $remote_cmd ( @remote_cmds ) {
say $pipe $remote_cmd;
}
close( $pipe );
一种选择可能是将您的命令列表写入脚本文件(以适合您的远程系统的任何格式 - bash、PowerShell 等)。 然后,您可以使用scp
将脚本复制到远程服务器,并ssh
远程运行脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.