mirror of
https://github.com/wfjm/w11.git
synced 2026-01-15 16:26:35 +00:00
59 lines
1.8 KiB
Perl
Executable File
59 lines
1.8 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
# $Id: telnet_wrapper 985 2018-01-03 08:59:40Z mueller $
|
|
#
|
|
# Copyright 2009-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
|
#
|
|
# This program is free software; you may redistribute and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free
|
|
# Software Foundation, either version 3, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
# for complete details.
|
|
#
|
|
# Revision History:
|
|
# Date Rev Vers Comment
|
|
# 2017-05-25 899 1.1 add 'r' --> reset and stty sane handling
|
|
# 2009-11-07 246 1.0 Initial version
|
|
#
|
|
|
|
use 5.14.0; # require Perl 5.14 or higher
|
|
use strict; # require strict checking
|
|
|
|
if (scalar(@ARGV) != 2) {
|
|
print STDERR "usage: telnet_wrapper host port\n";
|
|
exit 1;
|
|
}
|
|
|
|
my $host = $ARGV[0];
|
|
my $port = $ARGV[1];
|
|
|
|
print "$host $port\n";
|
|
|
|
my $telnet = `which telnet`;
|
|
chomp $telnet;
|
|
|
|
while(1) {
|
|
my $rc = system $telnet, $host, $port;
|
|
print STDERR "telnet failed with rc=$rc\n" if $rc != 0;
|
|
print "enter q or <^D> to quit, r for tty reset, or <ENTER> to reconnect: ";
|
|
|
|
my $buf = <STDIN>;
|
|
unless ($buf) { # quit if EOF
|
|
print "\n";
|
|
exit 0;
|
|
}
|
|
chomp $buf;
|
|
next if $buf eq ""; # <ENTER>
|
|
exit 0 if $buf eq "q"; # 'q'
|
|
if ($buf eq "r") { # 'r'
|
|
my $rc = system 'reset';
|
|
print STDERR "'reset' failed with rc=$rc\n" if $rc != 0;
|
|
$rc = system 'stty', 'sane';
|
|
print STDERR "'stty sane' failed with rc=$rc\n" if $rc != 0;
|
|
} else {
|
|
print "Invalid input '$buf', only ^D,<ENTER> or 'r' allowed\n";
|
|
}
|
|
}
|