ssh perl脚本未运行 [英] ssh perl script not running
问题描述
我正在尝试编写一个脚本,该脚本将在perl中ssh到远程计算机.
I am trying to write a script that will ssh to a remote machine in perl.
我不确定出什么问题,但是在运行脚本时,它会提示我输入root密码,并在输入密码后显示空白.
I'm not sure what's wrong but when I run the script, it prompts me for the root password and ends up with blank output after I give the password.
这是我的剧本:
#!/usr/bin/perl
use strict;
use warnings;
my @id=`ssh expert\@x.x.x.x`;
print"@id";
推荐答案
这就是您要求程序执行的操作.这行
That is what you have asked your program to do. This line
`ssh expert\@x.x.x.x`
- 使用给定参数启动一个运行ssh的新子进程
- 退出该子进程并返回ssh输出的所有文本
大概在连接后就需要与远程系统进行交互,因此您需要 perl 进程来连接至远程系统,或者您需要能够与远程系统进行监听和对话散列在退出之前已连接的子进程
You presumably need to interact with the remote system once you have connected, so you either need the perl process to connect to the remote system, or you need to be able to listen and talk to the subprocess that hash connected before it exits
第一个是迄今为止最简单的解决方案.如果您使用 Net :: OpenSSH
模块并阅读其文档然后您将看到可以通过创建一个对象来打开连接.然后,您可以使用该对象的 capture
方法
The first is by far the simplest solution. If you use the Net::OpenSSH
module and read its documentation then you will see that you can open a connection by creating an object. You can then send commands and retrieve the output using that object's capture
method
这篇关于ssh perl脚本未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!