perl - Perl 在不同的主机上运行子程序
问题描述
我是 perl 的新手。我有脚本,我需要跳转到不同的主机并比较 FS、环境等
我有一个主跳转服务器(MAIN_JUMP 和 5 个跳转服务器到不同的集群(CLUSTER_JUMP_1-5)。我在 MAIN_JUMP 上运行我的脚本,但我需要在 CLUSTER_JUMP_* 上运行一些子例程。在子例程中我跳转到集群中的特定主机。
是否可以通过 ssh 或某些 perl 模块直接在 CLUSTER_JUMP 上运行子程序?现在我使用双 ssh 到 CLUSTER_JUMP_* 然后到特定的主机。它在某些情况下可以正常工作,但例如由于引号,对 oracle 数据库的选择无法正常工作。
解决方案
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 风格编写的模块。
推荐阅读
- visual-c++ - 使用 CMAKE_CXX_FLAGS 和 MSVC14 生成地图文件
- cron - 每月第一个星期二的 NCRONTAB 用于 Azure 函数
- c++ - 在 Windows 上使用 C++ 运行 bash 脚本
- reactjs - 在 react+D3 中将更新逻辑与 useEffect 解耦
- html - 如何在图像文件中插入视频链接
- javascript - 如何使用 Javascript 从我的浏览器重定向到相机本机应用程序?
- react-native - React Native 钩子 - 正确使用 useEffect()?
- javascript - 如何使用带有 Javascript 的面向对象编程来操作 HTML DOM 元素
- halcon - 来自 HALCON 中的 3D 点的 2D
- python - Python - 正则表达式(Re.Escape,Re.Findall);如何:查找子字符串 + 字符串中子字符串之外的多个字符?