Telnet with optional login/pw and sending commands using perl
Ok Im new to perl script and trying to make a code and have searched the posts here related to telnet and logging and sending commands... I tried the same but did not work
Heres json file
{
"testbed":
"rps":
"RPS1":
"management": "192.168.40.2",
"pool": "2,4,5"
,
"RPS2":
"management": "192.168.40.20",
"pool": "2,5"
,
And my perl script is this
#!/usr/bin/perl -w
use warnings;
use strict;
use JSON;
use Talari::Automation::CLI;
use Data::Dumper;
use Net::Telnet();
use Expect;
#read json and print value of json
my $json;
local $/; #Enable 'slurp' mode
open my $fh, "<", "Persistent_path.json";
$json = <$fh>;
close $fh;
my $data = decode_json($json);
############RPS
use vars qw/ $rps $rpses $ip /;
#rps info from decoded $data alone stored in $rps of perl
my $rps = $data->'testbed'->'rps';
print Dumper($rps);
# loop to extract only mgt ip addresses of switches
foreach my $rpsinfo(keys %$rps)
my $rpses=$rps->$rpsinfo;
my $rpsip = $rpses->'management';
my @rpspool = $rpses->'pool';
my $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'die', );
$telnet->open("$rpsip");
$telnet->waitfor('/> $/');
$telnet->cmd('pshow');
and the output is pattern match timed-out at ./rps.pl line 38
and when logging in telnet manually, the prompt shows only >
I just wanted to login to telnet as easy as possible so I searched and saw Telnet module but its not giving output.
I also tried this code
system("telnet","$rpsip");
It works but I cannot send any commands like "pshow" using print command..
Anyone help me with this? I just want to make it simple and also, I have to modify code so that incase the connection fails, i want to try for 2 more times logging in then issue my commands to turn the ports on.
Thanks in advance. Also, is there a place where I can learn perl script mostly related to networking?
json perl networking
add a comment |
Ok Im new to perl script and trying to make a code and have searched the posts here related to telnet and logging and sending commands... I tried the same but did not work
Heres json file
{
"testbed":
"rps":
"RPS1":
"management": "192.168.40.2",
"pool": "2,4,5"
,
"RPS2":
"management": "192.168.40.20",
"pool": "2,5"
,
And my perl script is this
#!/usr/bin/perl -w
use warnings;
use strict;
use JSON;
use Talari::Automation::CLI;
use Data::Dumper;
use Net::Telnet();
use Expect;
#read json and print value of json
my $json;
local $/; #Enable 'slurp' mode
open my $fh, "<", "Persistent_path.json";
$json = <$fh>;
close $fh;
my $data = decode_json($json);
############RPS
use vars qw/ $rps $rpses $ip /;
#rps info from decoded $data alone stored in $rps of perl
my $rps = $data->'testbed'->'rps';
print Dumper($rps);
# loop to extract only mgt ip addresses of switches
foreach my $rpsinfo(keys %$rps)
my $rpses=$rps->$rpsinfo;
my $rpsip = $rpses->'management';
my @rpspool = $rpses->'pool';
my $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'die', );
$telnet->open("$rpsip");
$telnet->waitfor('/> $/');
$telnet->cmd('pshow');
and the output is pattern match timed-out at ./rps.pl line 38
and when logging in telnet manually, the prompt shows only >
I just wanted to login to telnet as easy as possible so I searched and saw Telnet module but its not giving output.
I also tried this code
system("telnet","$rpsip");
It works but I cannot send any commands like "pshow" using print command..
Anyone help me with this? I just want to make it simple and also, I have to modify code so that incase the connection fails, i want to try for 2 more times logging in then issue my commands to turn the ports on.
Thanks in advance. Also, is there a place where I can learn perl script mostly related to networking?
json perl networking
Pattern match timed-out at ./rps.pl line 38
: Use the debug features ofNet::Telnet
to see what prompt actually gets sent:Dump_Log => $filename,
:my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page showscode
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off >code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times
– Ryde
Nov 15 '18 at 13:20
add a comment |
Ok Im new to perl script and trying to make a code and have searched the posts here related to telnet and logging and sending commands... I tried the same but did not work
Heres json file
{
"testbed":
"rps":
"RPS1":
"management": "192.168.40.2",
"pool": "2,4,5"
,
"RPS2":
"management": "192.168.40.20",
"pool": "2,5"
,
And my perl script is this
#!/usr/bin/perl -w
use warnings;
use strict;
use JSON;
use Talari::Automation::CLI;
use Data::Dumper;
use Net::Telnet();
use Expect;
#read json and print value of json
my $json;
local $/; #Enable 'slurp' mode
open my $fh, "<", "Persistent_path.json";
$json = <$fh>;
close $fh;
my $data = decode_json($json);
############RPS
use vars qw/ $rps $rpses $ip /;
#rps info from decoded $data alone stored in $rps of perl
my $rps = $data->'testbed'->'rps';
print Dumper($rps);
# loop to extract only mgt ip addresses of switches
foreach my $rpsinfo(keys %$rps)
my $rpses=$rps->$rpsinfo;
my $rpsip = $rpses->'management';
my @rpspool = $rpses->'pool';
my $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'die', );
$telnet->open("$rpsip");
$telnet->waitfor('/> $/');
$telnet->cmd('pshow');
and the output is pattern match timed-out at ./rps.pl line 38
and when logging in telnet manually, the prompt shows only >
I just wanted to login to telnet as easy as possible so I searched and saw Telnet module but its not giving output.
I also tried this code
system("telnet","$rpsip");
It works but I cannot send any commands like "pshow" using print command..
Anyone help me with this? I just want to make it simple and also, I have to modify code so that incase the connection fails, i want to try for 2 more times logging in then issue my commands to turn the ports on.
Thanks in advance. Also, is there a place where I can learn perl script mostly related to networking?
json perl networking
Ok Im new to perl script and trying to make a code and have searched the posts here related to telnet and logging and sending commands... I tried the same but did not work
Heres json file
{
"testbed":
"rps":
"RPS1":
"management": "192.168.40.2",
"pool": "2,4,5"
,
"RPS2":
"management": "192.168.40.20",
"pool": "2,5"
,
And my perl script is this
#!/usr/bin/perl -w
use warnings;
use strict;
use JSON;
use Talari::Automation::CLI;
use Data::Dumper;
use Net::Telnet();
use Expect;
#read json and print value of json
my $json;
local $/; #Enable 'slurp' mode
open my $fh, "<", "Persistent_path.json";
$json = <$fh>;
close $fh;
my $data = decode_json($json);
############RPS
use vars qw/ $rps $rpses $ip /;
#rps info from decoded $data alone stored in $rps of perl
my $rps = $data->'testbed'->'rps';
print Dumper($rps);
# loop to extract only mgt ip addresses of switches
foreach my $rpsinfo(keys %$rps)
my $rpses=$rps->$rpsinfo;
my $rpsip = $rpses->'management';
my @rpspool = $rpses->'pool';
my $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'die', );
$telnet->open("$rpsip");
$telnet->waitfor('/> $/');
$telnet->cmd('pshow');
and the output is pattern match timed-out at ./rps.pl line 38
and when logging in telnet manually, the prompt shows only >
I just wanted to login to telnet as easy as possible so I searched and saw Telnet module but its not giving output.
I also tried this code
system("telnet","$rpsip");
It works but I cannot send any commands like "pshow" using print command..
Anyone help me with this? I just want to make it simple and also, I have to modify code so that incase the connection fails, i want to try for 2 more times logging in then issue my commands to turn the ports on.
Thanks in advance. Also, is there a place where I can learn perl script mostly related to networking?
json perl networking
json perl networking
asked Nov 15 '18 at 4:30
RydeRyde
113
113
Pattern match timed-out at ./rps.pl line 38
: Use the debug features ofNet::Telnet
to see what prompt actually gets sent:Dump_Log => $filename,
:my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page showscode
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off >code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times
– Ryde
Nov 15 '18 at 13:20
add a comment |
Pattern match timed-out at ./rps.pl line 38
: Use the debug features ofNet::Telnet
to see what prompt actually gets sent:Dump_Log => $filename,
:my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page showscode
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off >code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times
– Ryde
Nov 15 '18 at 13:20
Pattern match timed-out at ./rps.pl line 38
: Use the debug features of Net::Telnet
to see what prompt actually gets sent: Dump_Log => $filename,
: my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
Pattern match timed-out at ./rps.pl line 38
: Use the debug features of Net::Telnet
to see what prompt actually gets sent: Dump_Log => $filename,
: my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>
code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>
code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows
code
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off > code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times– Ryde
Nov 15 '18 at 13:20
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows
code
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off > code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times– Ryde
Nov 15 '18 at 13:20
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312470%2ftelnet-with-optional-login-pw-and-sending-commands-using-perl%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312470%2ftelnet-with-optional-login-pw-and-sending-commands-using-perl%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Pattern match timed-out at ./rps.pl line 38
: Use the debug features ofNet::Telnet
to see what prompt actually gets sent:Dump_Log => $filename,
:my $telnet = Net::Telnet->new( Timeout=>5, Dump_Log => 'telnet_debug.txt', Errmode=>'die', );
– Corion
Nov 15 '18 at 9:18
That was little helpful. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows <pre>
code
> >Type "help" for a list of commands. > >Make sure to set Telnet mode to Local Echo Off > > <pre>code
– Ryde
Nov 15 '18 at 13:13
That was little helpful.I used Input_log instead dump_log. Dump log shows in encrypt form. Now I know exactly where the issue is occurring. Script is logging in telnet but I think its not able to recognize prompt and send the "pshow" command I believe This is how my telnet login page shows
code
>Type "help" for a list of commands. >Make sure to set Telnet mode to Local Echo Off >code
Can you tell the regular regex format I should use in waitfor()?? ignore previous comment.. im new and it says I can edit only 5 times– Ryde
Nov 15 '18 at 13:20