从本地机器在远程服务器上执行 Perl 脚本 [英] Execute Perl script on remote server from local machine

查看:62
本文介绍了从本地机器在远程服务器上执行 Perl 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Perl 比较陌生,正在翻译一些 bash 脚本以将来自多个远程生产服务器的 Apache 日志解析为更有用的格式,以便在本地计算机上进行处理.我需要尽可能保持生产服务器整洁.因此,我的本地机器上有两个单独的 .pl 文件 - crawler.pl(以前称为 crawler.sh),负责从生产服务器获取有用的信息,以及reporter.pl(以前称为reporter.sh),负责运行爬虫并整理从生产服务器检索到的信息.

I am rather new to Perl and translating some bash scripts to parse Apache logs from several remote production servers into a more useful format for processing on a local machine. I need to keep the production servers as uncluttered as possible. As such, I have two separate .pl files on my local machine - crawler.pl (formerly crawler.sh), responsible for the grabbing the useful information from the production servers, and reporter.pl (formerly reporter.sh), responsible for running the crawler and collating the information retrieved from the production servers.

我想要完成的是 Perl 等价物:

What I'm looking to accomplish is the Perl equivalent of:

    ssh "user@host" 'bash -s' < $crawler

其中 $crawler 是本地机器上 crawler.sh 的物理位置.

where $crawler is (was) the physical location of crawler.sh on the local box.

我希望reporter.pl打开生产服务器的ssh连接并远程执行crawler.pl,效果如下:

I want reporter.pl to open an ssh connection the the production servers and remotely execute crawler.pl., something to the effect of:

    use Net::SSH qw(ssh);
    ssh($loginString,"perl -e $crawler");

这显然行不通,但希望你明白我在做什么.

which obviously doesn't work, but hopefully you understand what I'm driving at.

我知道可以通过将爬虫文件复制到生产服务器并在完成任务后将其删除来实现此目的;我正在寻找一个更优雅的解决方案,如果存在的话.

I know it's possible to accomplish this by copying the crawler file to the production servers and deleting it when it has completed its tasks; I'm after a more elegant solution, should one exist.

推荐答案

如果你不向脚本传递参数,它应该像

If you're not passing arguments to the script, it should be as simple as

ssh "user@host" perl <$爬虫

ssh "user@host" perl < $crawler

如果要传递命令行参数,只需使用-"占位符即可获得与 bash -s 相同的效果,即

If you want to pass command line args, just use a "-" placeholder to get the same affect as the bash -s, i.e.

ssh "user@host" 'perl - arg1 arg2' <$爬虫

ssh "user@host" 'perl - arg1 arg2' < $crawler

这篇关于从本地机器在远程服务器上执行 Perl 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆