【问题标题】:Perl run subroutine on different hostPerl 在不同的主机上运行子程序
【发布时间】:2020-11-13 01:06:25
【问题描述】:

我是 perl 新手。我有脚本需要跳转到不同的主机并比较 FS、环境等

我有一个主跳转服务器(MAIN_JUMP 和 5 个跳转服务器到不同的集群(CLUSTER_JUMP_1-5)。我在 MAIN_JUMP 上运行我的脚本,但我需要在 CLUSTER_JUMP_* 上运行一些子例程。在子例程中我跳转到集群中的特定主机。

是否可以通过 ssh 或一些 perl 模块直接在 CLUSTER_JUMP 上运行子程序?现在我使用双 ssh 到 CLUSTER_JUMP_* 然后到特定的主机。它在某些情况下可以正常工作,但例如由于引号导致对 oracle 数据库的选择无法正常工作。

【问题讨论】:

  • 您在寻找 perl RPC 模块吗?
  • 是这样的。我认为有可能创建一个主脚本,而这个子例程重写为小脚本。但我希望这个问题有更简单的解决方案。

标签: perl


【解决方案1】:

Object::Remote 会以非常简单的方式为您完成此操作...

use strict;
use warnings;
use feature 'say';
use Object::Remote;

####################################################################
# Note that My::File must be installed on the machines you want to
# run this on!
####################################################################
# package My::File;
# use Moo;
# has path => ( is => 'ro', required => 1 );
# sub size {
#   my $self = shift;
#   -s $self->path;
# }
# 1;
####################################################################

use My::File;

## find the size of a local file
my $file1 = My::File->new( path => '/etc/hostname' );
say $file1->size;

## find the size of a file on a remote host
my $conn  = Object::Remote->connect('host.example.net');  # ssh 
my $file2 = My::File->new::on( $conn, path => '/etc/hostname' );
say $file2->size;

更新: 为清楚起见,“My::File”没有什么特别之处。这只是您将编写并确保在您将远程访问的所有机器以及“客户端”机器上正确安装的模块的一个示例。它可以是任何以 OO 风格编写的模块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多