【问题标题】:How to implement a command history on a telnet client? (up/down arrows)如何在 telnet 客户端上实现命令历史记录? (上/下箭头)
【发布时间】:2012-04-06 06:18:28
【问题描述】:

我有一个接受 telnet 连接进行管理的服务器。我想念命令历史,所以我想让我的 telnet 会话支持它。我的问题:

1)我必须在服务器端实现,所以服务器会将过去的命令发送给客户端,然后客户端可以重新执行?

2) 是否有在 telnet 客户端中实现此功能(不与服务器混淆)?

如果答案是 1),那么我需要知道如何在我的 telnet 会话中捕获和发送向上和向下箭头键,而无需按 Enter。

【问题讨论】:

    标签: linux perl automation admin telnet


    【解决方案1】:

    这不是服务器问题。只需将rlwrap 与您的远程登录客户端一起使用。无需编程即可为您提供readline

    $ rlwrap telnet server port
    

    (我实际上使用nc 而不是telnet,因为它更易于使用且更健壮。)

    【讨论】:

    • @chrisapotek 请改用 Ctrl-D。
    【解决方案2】:

    使用 socat:

    socat readline,history=$HOME/.telnet_history TCP:host:23
    

    【讨论】:

    • 注意:如果省略history,则使用文件$HOME/.history
    • 不适用于最新的 Ubuntu/Debian,不幸的是,due to a licensing issue
    【解决方案3】:

    我假设这是您用 Perl 编写的服务,基于您的标签。

    您可以使用 CPAN 中的 Term::ReadLine 模块来做您想做的事情。来自 CPAN 网站,这是一个基本示例:

    use Term::ReadLine;
        my $term = Term::ReadLine->new('My Management Service');
        my $prompt = "Enter your management command: ";
        my $OUT = $term->OUT || \*STDOUT;
        while ( defined ($_ = $term->readline($prompt)) ) {
            my $res = eval($_);
            warn $@ if $@;
            print $OUT $res, "\n" unless $@;
            $term->addhistory($_) if /\S/;
        }
    

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      相关资源
      最近更新 更多