在 SSH 终端中执行的命令显示额外的行内容 [英] Command executed in SSH terminal displays extra line contents

查看:30
本文介绍了在 SSH 终端中执行的命令显示额外的行内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Net::SSH::Expect perl 模块我尝试连接到服务器并且连接成功.但是当它在连接的服务器中执行命令并在当前窗口中显示输出时,它会显示额外的输出行.

Using Net::SSH::Expect perl module I tried to connect to the server and connection is success. But when its executing the command in connected server and displaying output in current window it displays extra line of output.

下面是我的代码

#!/usr/bin/perl 

use Net::SSH::Expect;

my $ssh = Net::SSH::Expect->new (
    host => 'hostip', #deb-2-scripting ip
    user => 'user',
    password => 'password',
    raw_pty => 1
);

$ssh->run_ssh() or die "SSH process couldn't start: $!";


$ssh->waitfor('password: ');

$ssh->send("password");

$ssh->exec("stty -echo");

my $hostname = $ssh->exec('hostname');
print "HOST:$hostname\n";

$ssh->close();

输出如下:

[vinod@deb-3-serv1 TEST_DIR]$ perl test_ssh.pl
HOST:deb-2-scripting
[user@deb-2-scripting(Host) ~]$

当我执行 test_ssh.pl

HOST:deb-2-scripting

不应该打印最后一行,这显示在我上面的输出结果中.

and last line shouldn't be printed which shows in my output result above.

推荐答案

通过 no_terminal =>1 构造函数的选项.

Pass the no_terminal => 1 option to the constructor.

my $ssh = Net::SSH::Expect->new (
    host => 'hostip', #deb-2-scripting ip
    user => 'user',
    password => 'password',
    raw_pty => 1,
    no_terminal => 1,
);

这将阻止 ssh 服务器分配伪 tty,并且远程 shell 在不在 tty 中运行时不应打印提示.

That will prevent the ssh server from allocating a pseudo-tty, and the remote shell should not print a prompt when not running in a tty.

这篇关于在 SSH 终端中执行的命令显示额外的行内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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