简体   繁体   English

使用ssh在另一个脚本中运行perl脚本

[英]Run a perl script inside another script using ssh

I have a perl script where I need to connect to another machine using ssh and there run another perl script. 我有一个perl脚本,我需要使用ssh连接到另一台机器,然后运行另一个perl脚本。 I tried using this line: 我尝试使用这一行:

system("ssh $admin_server 'perl /Perl/scripts/capture_server_restarts_gse.pl $month $date'");

But everytime the script gets to that line, I get the prompt for the remote machine and the script doesn't run. 但每次脚本到达该行时,我都会收到远程计算机的提示,并且脚本不会运行。

How can I fix this so the script runs automatically on the other machine without showing the prompt. 我该如何解决这个问题,以便脚本在另一台机器上自动运行而不显示提示。

Note: I don't need the password and user to connect to the remote machine we already solved that. 注意:我不需要密码和用户连接到我们已经解决的远程机器。

Why not copy your public key onto the other machine ? 为什么不将您的公钥复制到另一台机器上? That way you'll be pre-authorised. 那样你就会被预先授权。

Here are the instructions on how to do this using ssh-keygen 以下是如何使用ssh-keygen执行此操作的说明

Otherwise you have to feed ssh with your password, and that's tricky since ssh normally takes input from a tty and you have to configure your script with the password. 否则你必须用你的密码提供ssh ,这很棘手,因为ssh通常从tty获取输入,你必须使用密码配置你的脚本。

The SSH server may be configured to run always some custom shell instead of the command passed from the client. SSH服务器可以配置为始终运行一些自定义shell而不是从客户端传递的命令。

Try just running some simple command from the command line, ie: 尝试从命令行运行一些简单的命令,即:

  ssh server ls

A less likely possibility is that the perl variables interpolated into the system argument could contain some shell metacharacters requiring better escaping. 不太可能的是,插入到系统参数中的perl变量可能包含一些需要更好转义的shell元字符。 For instance, a semicolon inside $admin_server. 例如,$ admin_server中的分号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM