in reply to Newbee needs help
Hello again Anonymous Monk,
I noticed that the monks have helped you already and propose some alternative solutions to your problem.
As blindluke guessed you are propably using Net::Telnet, but I would also like to propose an alternative solution that it will work if the router supports ssh.
At this point I remembered that in the past I used Net::OpenSSH on a Sierra modem to execute a few commands (if it supports ssh).
I created a sample of code that it does exactly what you need and pipes the output to your local OS. I am using a command for Linux, so you have to change the command and test it. I think it will work, I am not 100% sure because you said it is VoIP router but worth the effort of trying.
Sample of running code with output printed from the file.
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my $host = "127.0.0.1"; # remote IP my $port = 22; # ssh default 22 change it my $passwd = "username"; my $user = "password"; my %opts = ( passwd => $passwd, port => $port, user => $user ); my $ssh = Net::OpenSSH->new( $host , %opts ); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; my ($rout, $pid) = $ssh->pipe_out("vmstat") or die "pipe_out method failed: " . $ssh->error; open my $write, ">", "test.txt" or die $!; while (<$rout>) { print $write $_; } close $rout; close $write; open my $read, "<", "test.txt" or die $!; while (my $row = <$read>) { chomp $row; print "$row\n"; } close $read; __END__ Check also the test.txt file it contains the same output procs -----------memory---------- ---swap-- -----io---- -system-- ---- +--cpu----- r b swpd free buff cache si so bi bo in cs us s +y id wa st 1 0 68716 390444 9520 674036 0 1 25 27 217 235 8 +2 89 1 0
I hope this helps, let me know if it worked.
Ps: please change the title of your question to something more appropriate, read I want to ask a question of the Perl Monks; where do I start?, How do I post a question effectively? and importantly Select an informative title.. It will only take you a few minutes.
|
|---|