RE: configure a switch via ssh with a perl program
Hi Lee You can use Net::SSH2 or Net::SSH::Perl to log into your switches and run any commands you need to. I actually use Net::SSH2 for this...There are a lot of examples around. You just need to do something like this... This code is only an example. my $ssh2 = Net::SSH2->new(); $ssh2->connect( $YOURSERVERHERE); # can be ip or fqdn or just the device name is if it has an entry in dns $ssh2->auth_password($USERNAME_TO_SWITCH, $PASSWORD); $channel = $ssh2->channel(); $channel->exec($YOUR_CMD_HERE); while ($channel->read($buf, $buflen)) { $result .=$buf; } Then you have to parse what you get back. Here is a link to stack overflow with an example to using Net::SSH::Perl which looks a bit easier. http://stackoverflow.com/questions/16594963/perl-ssh-into-device Trac -Original Message- From: lee [mailto:l...@yagibdah.de] Sent: Tuesday, July 12, 2016 7:33 PM To: beginners@perl.org Subject: Re: configure a switch via ssh with a perl program Shekar writes: > Hi Lee, > > If you can login to your switch via ssh, run required commands on the > switch and exit out, you should be able to simulate the same via > Net::OpenSSH or Net::SSH::Perl Yes, that's what I was thinking. Only it takes time to program, that's a problem. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: configure a switch via ssh with a perl program
Shekar writes: > Hi Lee, > > If you can login to your switch via ssh, run required commands on the > switch and exit out, you should be able to simulate the same via > Net::OpenSSH or Net::SSH::Perl Yes, that's what I was thinking. Only it takes time to program, that's a problem. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: configure a switch via ssh with a perl program
Hi Lee, If you can login to your switch via ssh, run required commands on the switch and exit out, you should be able to simulate the same via Net::OpenSSH or Net::SSH::Perl Cheers, Shekar On Mon, Jul 4, 2016 at 8:18 PM, lee wrote: > Shlomi Fish writes: > > > Hi lee, > > > > On Mon, 04 Jul 2016 04:18:22 +0200 > > lee wrote: > > > >> Hi, > >> > >> would it be possible to use something like Net::SSH::Perl to > >> automatically alter the configuration of a switch into which I can log > >> in manually via ssh? > > [SNIPPED] > >> Once per hour or so, the connections could be switched again to check > >> whether the one on port 2 is working again. So I'd be writing a deamon > >> in perl for this --- not a problem, except for communicating with the > >> switch. From the documentation of Net::SSH::Perl, it's not clear to me > >> how to receive any output the switch might send. > >> > >> > >> What would you suggest how to communicate with the switch? Is > >> Net::SSH::Perl the right tool to use? > >> > > > > It should be possible to use one SSH module or another for this - see > > http://perl-begin.org/uses/remote-login-and-commands/#ssh . Regarding > your > > question about Net::SSH::Perl, I believe you need the $out, $err, etc. > from > > https://metacpan.org/pod/Net::SSH::Perl#out-err-exit-ssh-cmd-cmd-stdin > > Thank you! I'm not set on a particular module, Net::SSH::Perl is only > what I found when I was looking. Net::OpenSSH looks better to me. > > I guess I'll have to try it out and see if it works. The ssh > implementation the switch uses is probably somewhat different from the > implementations these modules have been made to work with, so that could > give me trouble. But it works fine when I just ssh into the switch, so > why shouldn't it work. > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: configure a switch via ssh with a perl program
Shlomi Fish writes: > Hi lee, > > On Mon, 04 Jul 2016 04:18:22 +0200 > lee wrote: > >> Hi, >> >> would it be possible to use something like Net::SSH::Perl to >> automatically alter the configuration of a switch into which I can log >> in manually via ssh? > [SNIPPED] >> Once per hour or so, the connections could be switched again to check >> whether the one on port 2 is working again. So I'd be writing a deamon >> in perl for this --- not a problem, except for communicating with the >> switch. From the documentation of Net::SSH::Perl, it's not clear to me >> how to receive any output the switch might send. >> >> >> What would you suggest how to communicate with the switch? Is >> Net::SSH::Perl the right tool to use? >> > > It should be possible to use one SSH module or another for this - see > http://perl-begin.org/uses/remote-login-and-commands/#ssh . Regarding your > question about Net::SSH::Perl, I believe you need the $out, $err, etc. from > https://metacpan.org/pod/Net::SSH::Perl#out-err-exit-ssh-cmd-cmd-stdin Thank you! I'm not set on a particular module, Net::SSH::Perl is only what I found when I was looking. Net::OpenSSH looks better to me. I guess I'll have to try it out and see if it works. The ssh implementation the switch uses is probably somewhat different from the implementations these modules have been made to work with, so that could give me trouble. But it works fine when I just ssh into the switch, so why shouldn't it work. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: configure a switch via ssh with a perl program
Hi lee, On Mon, 04 Jul 2016 04:18:22 +0200 lee wrote: > Hi, > > would it be possible to use something like Net::SSH::Perl to > automatically alter the configuration of a switch into which I can log > in manually via ssh? [SNIPPED] > Once per hour or so, the connections could be switched again to check > whether the one on port 2 is working again. So I'd be writing a deamon > in perl for this --- not a problem, except for communicating with the > switch. From the documentation of Net::SSH::Perl, it's not clear to me > how to receive any output the switch might send. > > > What would you suggest how to communicate with the switch? Is > Net::SSH::Perl the right tool to use? > It should be possible to use one SSH module or another for this - see http://perl-begin.org/uses/remote-login-and-commands/#ssh . Regarding your question about Net::SSH::Perl, I believe you need the $out, $err, etc. from https://metacpan.org/pod/Net::SSH::Perl#out-err-exit-ssh-cmd-cmd-stdin Regards, Shlomi Fish -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/