Open VFagionato opened 3 years ago
I have kind of a similar problem. When running the following code:
const Telnet = require('telnet-client');
const code = `
perl << 'EEOF' | sed 's/^/...OUTPUTBEGIN /'
#!/usr/bin/perl -w
use strict;
use 5.10.0;
my $count = 0;
my $physc = 0;
my $entc = 0;
my $used = -1;
my $smtVal;
my $lcpuVal;
my %config = ();
my %paraIndex = ();
my $vmstat = \`vmstat -t 15 1|tail -1\`;
my @temp = split / +/, $vmstat;
my $idle = $temp[-4];
$used = 100 - $idle;
if ( $used == -1 ) {
print "CPU_Usage: match_error\n";
print \`echo EOF\`;
}
else {
$used = sprintf "%.2f", $used;
print "CPU_Usage: $used\n";
print \`echo EOF\`;
}
EEOF
echo definiteend
exit
`;
const cfg = {
host: '127.0.0.1',
port: 23,
username: 'fakeuser',
password: 'fakepass',
shellPrompt: '$',
removeEcho: 100,
debug: true,
timeout: 5000
};
(async (cfg) => {
const telnet = new TelnetConnection();
await telnet.connect(cfg);
console.log(await telnet.exec(code));
})(cfg);
Sometimes it will print out the correct output:
ok@pop-os:~/Code/Upwork/ssh2_api$ node telnetExample.js
/'
#!/usr/bin/perl -w
use strict;
use 5.10.0;
my $count = 0;
my $physc = 0;
my $entc = 0;
my $used = -1;
my $smtVal;
my $lcpuVal;
my %config = ();
my %paraIndex = ();
my $vmstat = `vmstat -t 15 1$ |tail -1`;
my @temp = split / +/, $vmstat;
my $idle = $temp[-4];
$used = 100 - $idle;
if ( $used == -1 ) {
print "CPU_Usage: match_error\n";
print `echo EOF`;
}
else {
$used = sprintf "%.2f", $used;
print "CPU_Usage> : $used\n";
print `echo EOF`;
}
EEOF
echo definiteend
exit
CPU_Usage: 100.00
EOF
$ definiteend
Other times, it will cut off and just display the input I sent it:
ok@pop-os:~/Code/Upwork//ssh2_api$ node telnetExample.js
/'
#!/usr/bin/perl -w
use strict;
use 5.10.0;
my $count = 0;
my $physc = 0;
my $entc = 0;
my $used = -1;
my $smtVal;
my $lcpuVal;
my %config = ();
my %paraIndex = ();
my $vmstat = `vmstat -t 15 1|tail -1`;
my @temp = split / +/, $vmstat;
my $idle = $temp[-4];
$used = 100 - $idle;
if ( $used == -1 ) {
print "CPU_Usage: match_error\n";
print `echo EOF`;
}
else {
$used = sprintf "%.2f",$ $used;
print "CPU_Usage: $used\n";
print `echo EOF`;
}
EEOF
echo definiteend
exit
It's about 50/50 which happens, and I have no idea what's changing when it works or not and how I can make it always work.
could try this:
let params= {
host: "128.223.51.102",
port: 23,
timeout: 60000,
pageSeparator: '--More--',
negotiationMandatory: false,
echoLines: 2000,
socketConnectOptions: {
highWaterMark: 64 * 1024 * 16
}
}
i using a telnet of routeviews.org.
I can connected and send a command to the telnet, but the response comes incomplete.
bellow is my configs and code.
and the response is:
In addition to showing the welcome message on the return, it does not show me the full json that telnet returns.
The json is quite large, but I need it complete for my application
Am I doing something wrong?