Hey All! I'm very new to Perl and coding in general. I've been trying to put together a script that to pass some basic ssh commands from a windows system to a Linux box. I was able to get this code to work without issue:
use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect("hostname") or die "Unable to connect to host $@ \n"; $ssh2->auth_password('username','password') or die "Unable to login $@ +\n"; my $chan=$ssh2->channel(); $chan->shell(); print $chan "ifconfig\n"; print "LINE : $_" while <$chan>; print $chan "top\n"; print "LINE : $_" while <$chan>; $chan->close;
However the same basic code but edited to accept user input does not.
use warnings; use strict; use Net::SSH2; print "Hostame: "; my $host = <STDIN>; print "Username: "; my $user = <STDIN>; print "Password: "; my $pass = <STDIN>; my $ssh2 = Net::SSH2->new(); $ssh2->connect($host) or die "Unable to connect $host $@ \n"; $ssh2->auth_password($user,$pass) or die "Unable to login $@ \n"; my $chan=$ssh2->channel(); $chan->shell(); print $chan "ifconfig\n"; print "LINE : $_" while <$chan>; print $chan "top\n"; print "LINE : $_" while <$chan>; $chan->close;
That code returns an error of "No such host is known". Can someone help point out what i'm going wrong?
In reply to SSH2 user input not working. by Goggal0r
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |