问题描述
我对 openssh 还很陌生,我正在编写一个框架来自动执行一些任务。 我知道通过 ssh 向远程虚拟机发送命令来做一些事情很容易。但是我想向在我的远程虚拟机中运行的类似 CLI 的服务发送一些命令。 为了更好地解释它:
[c:\~]$ ssh [email protected]
Connecting to x.x.x.x:22...
Connection established.
To escape to local shell,press 'Ctrl+Alt+]'.
[root@vm1 ~]# ssh admin@0
admin@0's password:
admin connected from 127.0.0.1 using ssh on vm1
Your last successful login was at 2021-2-1 19:25:27
Your last successful login was from 127.0.0.1
admin@vm1>
这就是我正在做的, a) 我通过 ssh 登录到我的远程机器。 b) 然后我登录到在我的虚拟机中运行的类似 CLI 的服务。
所以我想要实现的是,我想在我的虚拟机上的 CLI 上运行一些命令。我的 perl 脚本目前看起来像这样。 (注意:我的 perl 脚本完全在不同的虚拟机中运行)
#! /usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
use IO::Pty;
print "New connection\n";
my $ssh = Net::OpenSSH->new("x.x.x.x",user=>'admin',password=>'password',port=>22,timeout=>30);
$ssh->error and die "Could not connect\n". $ssh->error;
my $cmd = $ssh->pipe_out("show alarm");
while(<$cmd>){
print "$_";
}
close $cmd;
undef $ssh;
这是我看到的 o/p:
root@debian:~# perl automate.pl
New connection
Your last successful login was at 2021-2-1 19:40:20
Your last successful login was from x.x.x.x
^C
root@debian:~#
我期望的 o/p 用于命令“show alarm”,但看起来该命令没有到达我的目标机器的 CLI。 如果能得到大家的指导会很有帮助。 谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)