Ask a Question related to PERL Modules, Design and Development.
-
Jaws #1
Net::SSH::Perl
Hi all,
I am currently using Net::SSH::Perl module to login in my remote machine.
Below is my code:
==================================
#!/usr/bin/perl
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="111.222.333.444";
my $ssh = Net::SSH::Perl->new($host,"'1,2'");
$ssh->login($user, $pass);
$ssh->cmd("my_command");
==================================
the output of the last line requires me to input username and password. How
can do it using this module? I've tried to search in the manual of the
package but i didn't find one to answer my question and even in the web so i
decided to ask help from you.
Thanks.
jaws
---------------
Computer system security is a journey, not a destination.
Jaws Guest
-
Off Topic: Active Perl Native Windows / cygwin perl
I have both activestate windows native perl installed and the default cygwin perl. How can I have the cygwin shell use the windows perl rather... -
Control a non-perl image viewer from perl script
Below is a (non-finished) script that trys to run a linux viewer called eog (eye of gnome) in a script that will eventually allow me to power thru... -
Re : Installing CPAN Perl Modules with Activestate Perl 5. v5.8
Hi, In the process of trying to get perl modules installed, I downloaded over 300 Activestate specific perl modules and they work fine (of the ones... -
Effeciency question - perl scripts v's perl exe's
Max Adams wrote: The only existing Perl compiler is part of perl. Anything else is just a packager that puts a perl, required modules, and the... -
Designing Interfaces with Perl and Perl APIs
Hi, I am a long date perl programmer, and from time to time, I am having the same trouble: - To design interfaces for a self contained... -
Zentara #2
Re: Net::SSH::Perl
On Wed, 3 Sep 2003 12:54:07 +0800, [email]jaws@skyinet.net[/email] (Jaws) wrote:
#!/usr/bin/perl>Hi all,
>
>I am currently using Net::SSH::Perl module to login in my remote machine.
>Below is my code:
>
>==================================
>#!/usr/bin/perl
>
>use Net::SSH::Perl;
>
>$user="jaws";
>$pass="password";
>$host="111.222.333.444";
>
>my $ssh = Net::SSH::Perl->new($host,"'1,2'");
>$ssh->login($user, $pass);
>$ssh->cmd("my_command");
>==================================
>
>the output of the last line requires me to input username and password. How
>can do it using this module? I've tried to search in the manual of the
>package but i didn't find one to answer my question and even in the web so i
>decided to ask help from you.
use strict;
use warnings;
use Net::SSH::Perl;
my $user = "zz";
my $password = "ztest";
my @hosts = qw(localhost zentara.zentara.net);
foreach my $host (@hosts){
my $cmd = "/usr/bin/uptime";
my $ssh = Net::SSH::Perl->new( $host, port => 22 ,debug => 1);
$ssh->login($user,$password);
my($out) = $ssh->cmd($cmd);
my ($time,$uptime) = (split /\s+/,$out)[1,3];
chop $uptime;
print "$out\n";
print "$host has been up $uptime\n";
}
Zentara Guest
-
wiggins@danconia.org #3
Re: Net::SSH::Perl
------------------------------------------------
On Thu, 04 Sep 2003 14:23:44 -0400, zentara <zentara@highstream.net> wrote:
Not sure that got to the OPs question unless you have a really weird uptime command that expects input. To me the best option is to put a script out on the remote host that handles the local inputs/outputs and then switch your 'cmd' call to call that script rather than the program directly.> On Wed, 3 Sep 2003 12:54:07 +0800, [email]jaws@skyinet.net[/email] (Jaws) wrote:
>>> >Hi all,
> >
> >I am currently using Net::SSH::Perl module to login in my remote machine.
> >Below is my code:
> >
> >==================================
> >#!/usr/bin/perl
> >
> >use Net::SSH::Perl;
> >
> >$user="jaws";
> >$pass="password";
> >$host="111.222.333.444";
> >
> >my $ssh = Net::SSH::Perl->new($host,"'1,2'");
> >$ssh->login($user, $pass);
> >$ssh->cmd("my_command");
> >==================================
> >
> >the output of the last line requires me to input username and password. How
> >can do it using this module? I've tried to search in the manual of the
> >package but i didn't find one to answer my question and even in the web so i
> >decided to ask help from you.
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Net::SSH::Perl;
>
> my $user = "zz";
> my $password = "ztest";
> my @hosts = qw(localhost zentara.zentara.net);
>
> foreach my $host (@hosts){
> my $cmd = "/usr/bin/uptime";
> my $ssh = Net::SSH::Perl->new( $host, port => 22 ,debug => 1);
> $ssh->login($user,$password);
>
> my($out) = $ssh->cmd($cmd);
> my ($time,$uptime) = (split /\s+/,$out)[1,3];
> chop $uptime;
> print "$out\n";
> print "$host has been up $uptime\n";
> }
If that is not possible and the command is expecting its input on STDIN and you don't need to worry about what the prompt was then you should check the docs again, in particular:
"($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])
If $stdin is provided, it's supplied to the remote command $cmd on standard input."
If you really need to work with an interactive interface you will probably have to massage the underlying socket/buffer/packets, etc. or you might be able to do something with the 'shell' method attached to some local filehandles that handle the interactive component for you, but yikes.
Though I don't usually suggest it you might consider the 'Expect' module and calling 'ssh' on the command line.
[url]http://danconia.org[/url]
wiggins@danconia.org Guest
-
chesucat@freeshell.org #4
Re: Net::SSH::Perl
In comp.lang.perl.misc blob <jaws@skyinet.net> wrote:
b>Hi all,
b>
b>Below is my script that will be used to connect to a remote host and
b>change my password automatically:
b>
b>===========================================
b>#!/usr/bin/perl
b>
b>
b>use strict();
b>use Net::SSH::Perl;
b>
<snipped>
b>Does anybody has an idea what's missing or wrong with my script?
b>
I didn't know strict was functions?
chesucat
--
[email]chesucat@sdf.lonestar.org[/email]
no fortune!:-(
chesucat@freeshell.org Guest
-
get-fuzzy #5
Re: Net::SSH::Perl
Sorry, I cant comment on the perl as yet but, are you not in the least bit
worried that someone might hack into your base system - get the unencrypted
password (old password) then log on - using ssh to the other box ?
ssh is not 100% flawless
From a security point of view it is a nightmare, from a SA point of view - I
can see where you are coming from !
Just curious is all
"blob" <jaws@skyinet.net> wrote in message news:3f57f2ae@news.skyinet.net...> Hi all,
>
> Below is my script that will be used to connect to a remote host and
> change my password automatically:
>
> ===========================================
> #!/usr/bin/perl
>
>
> use strict();
> use Net::SSH::Perl;
>
>
> $user="jaws";
> $pass="password";
> $host="xxx.xxx.xxx.xxx";
> $old_password="password";
> $new_password="newpass";
>
>
> my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
> $ssh->login($user, $pass);
>
>
> $ssh->register_handler("stderr", sub {
> my($channel, $buffer) = @_;
> my $str = $buffer->bytes;
>
>
> if ($str eq "Enter login password: ") {
> $channel->send_data($old_password);
> }
>
>
> elsif ($str eq "New password: ") {
> $channel->send_data($new_password);
> }
>
> elsif ($str eq "Re-enter new password: ") {
> $channel->send_data($new_password);
> }
> });
> $ssh->cmd('passwd');
> ==========================================
>
> After running the program, my password didnt changed I was still able to
> connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
>
> Thanks.
>
> Jaws
>
get-fuzzy Guest
-
get-fuzzy #6
Re: Net::SSH::Perl
Sorry, I cant comment on the perl as yet but, are you not in the least bit
worried that someone might hack into your base system - get the unencrypted
password (old password) then log on - using ssh to the other box ?
ssh is not 100% flawless
From a security point of view it is a nightmare, from a SA point of view - I
can see where you are coming from !
Just curious is all
"blob" <jaws@skyinet.net> wrote in message news:3f57f2ae@news.skyinet.net...> Hi all,
>
> Below is my script that will be used to connect to a remote host and
> change my password automatically:
>
> ===========================================
> #!/usr/bin/perl
>
>
> use strict();
> use Net::SSH::Perl;
>
>
> $user="jaws";
> $pass="password";
> $host="xxx.xxx.xxx.xxx";
> $old_password="password";
> $new_password="newpass";
>
>
> my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
> $ssh->login($user, $pass);
>
>
> $ssh->register_handler("stderr", sub {
> my($channel, $buffer) = @_;
> my $str = $buffer->bytes;
>
>
> if ($str eq "Enter login password: ") {
> $channel->send_data($old_password);
> }
>
>
> elsif ($str eq "New password: ") {
> $channel->send_data($new_password);
> }
>
> elsif ($str eq "Re-enter new password: ") {
> $channel->send_data($new_password);
> }
> });
> $ssh->cmd('passwd');
> ==========================================
>
> After running the program, my password didnt changed I was still able to
> connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
>
> Thanks.
>
> Jaws
>
get-fuzzy Guest
-
Anno Siegel #7
Re: Net::SSH::Perl
<chesucat@freeshell.org> wrote in comp.lang.perl.misc:
It is not, but the call "use strict()" doesn't have any effect.> In comp.lang.perl.misc blob <jaws@skyinet.net> wrote:
> b>Hi all,
> b>
> b>Below is my script that will be used to connect to a remote host and
> b>change my password automatically:
> b>
> b>===========================================
> b>#!/usr/bin/perl
> b>
> b>
> b>use strict();
> b>use Net::SSH::Perl;
> b>
> <snipped>
> b>Does anybody has an idea what's missing or wrong with my script?
> b>
>
> I didn't know strict was functions?
The part in "()" is interpreted as an import list to the strict pragma
(which is technically a module). Since it is empty, strict's import
function isn't called, and no strictures are activated.
This is unlikely to be the cause of the OPs problem, but it doesn't
bode well for the rest of the code.
Anno
Anno Siegel Guest
-
blob #8
Net::SSH::Perl
Hi all,
Below is my script that will be used to connect to a remote host and
change my password automatically:
===========================================
#!/usr/bin/perl
use strict();
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="xxx.xxx.xxx.xxx";
$old_password="password";
$new_password="newpass";
my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
$ssh->login($user, $pass);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
if ($str eq "Enter login password: ") {
$channel->send_data($old_password);
}
elsif ($str eq "New password: ") {
$channel->send_data($new_password);
}
elsif ($str eq "Re-enter new password: ") {
$channel->send_data($new_password);
}
});
$ssh->cmd('passwd');
==========================================
After running the program, my password didnt changed I was still able to
connect using the old password.
Does anybody has an idea what's missing or wrong with my script?
Thanks.
Jaws
blob Guest
-
blob #9
Net::SSH::Perl
Hi all,
Below is my script that will be used to connect to a remote host and
change my password automatically:
===========================================
#!/usr/bin/perl
use strict();
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="xxx.xxx.xxx.xxx";
$old_password="password";
$new_password="newpass";
my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
$ssh->login($user, $pass);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
if ($str eq "Enter login password: ") {
$channel->send_data($old_password);
}
elsif ($str eq "New password: ") {
$channel->send_data($new_password);
}
elsif ($str eq "Re-enter new password: ") {
$channel->send_data($new_password);
}
});
$ssh->cmd('passwd');
==========================================
After running the program, my password didnt changed I was still able to
connect using the old password.
Does anybody has an idea what's missing or wrong with my script?
Thanks.
Jaws
blob Guest
-
James Willmore #10
Re: Net::SSH::Perl
On Fri, 05 Sep 2003 10:07:49 -0800
blob <jaws@skyinet.net> wrote:<sniped for brevity>> Hi all,
>
> Below is my script that will be used to connect to a remote host and
>
> change my password automatically:Just a suggestion - you may wish to use one of the Expect modules for>
> After running the program, my password didnt changed I was still
> able to connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
what you're doing. Expect is, IMHO, better suited for this task. And
in true Perl fashion, there is a module to interact with Expect :)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
for more information.
a fortune quote ...
Hlade's Law: If you have a difficult task, give it to a lazy
person -- they will find an easier way to do it.
James Willmore Guest
-
James Willmore #11
Re: Net::SSH::Perl
On Fri, 05 Sep 2003 10:07:49 -0800
blob <jaws@skyinet.net> wrote:<sniped for brevity>> Hi all,
>
> Below is my script that will be used to connect to a remote host and
>
> change my password automatically:Just a suggestion - you may wish to use one of the Expect modules for>
> After running the program, my password didnt changed I was still
> able to connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
what you're doing. Expect is, IMHO, better suited for this task. And
in true Perl fashion, there is a module to interact with Expect :)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
for more information.
a fortune quote ...
Hlade's Law: If you have a difficult task, give it to a lazy
person -- they will find an easier way to do it.
James Willmore Guest
-
Nico Coetzee #12
Re: Net::SSH::Perl
On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:
Instead of waiting for the exact string, why not use regular expresions,> Hi all,
>
> Below is my script that will be used to connect to a remote host and
> change my password automatically:
>
> ===========================================
> #!/usr/bin/perl
>
>
> use strict();
> use Net::SSH::Perl;
>
>
> $user="jaws";
> $pass="password";
> $host="xxx.xxx.xxx.xxx";
> $old_password="password";
> $new_password="newpass";
>
>
> my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
> $ssh->login($user, $pass);
>
>
> $ssh->register_handler("stderr", sub {
> my($channel, $buffer) = @_;
> my $str = $buffer->bytes;
>
>
> if ($str eq "Enter login password: ") {
> $channel->send_data($old_password);
> }
>
>
> elsif ($str eq "New password: ") {
> $channel->send_data($new_password);
> }
>
> elsif ($str eq "Re-enter new password: ") {
> $channel->send_data($new_password);
> }
> });
> $ssh->cmd('passwd');
> ==========================================
>
> After running the program, my password didnt changed I was still able to
> connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
>
> Thanks.
>
> Jaws
which might eliminate typo's. Something like:
if ($str =~ /enter\s+login\s+password/i ) {
$channel->send_data($old_password);
}
elsif ($str =~ /new\s+password/i ) {
$channel->send_data($new_password);
}
elsif ($str =~ /re.enter\s+new\s+password/i ) {
$channel->send_data($new_password);
}
Cheers
--
Nico Coetzee
[url]http://www.itfirms.co.za/[/url]
[url]http://za.pm.org/[/url]
[url]http://forums.databasejournal.com/[/url]
To the systems programmer, users and applications serve only to provide a
test load.
Nico Coetzee Guest
-
Nico Coetzee #13
Re: Net::SSH::Perl
On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:
Instead of waiting for the exact string, why not use regular expresions,> Hi all,
>
> Below is my script that will be used to connect to a remote host and
> change my password automatically:
>
> ===========================================
> #!/usr/bin/perl
>
>
> use strict();
> use Net::SSH::Perl;
>
>
> $user="jaws";
> $pass="password";
> $host="xxx.xxx.xxx.xxx";
> $old_password="password";
> $new_password="newpass";
>
>
> my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
> $ssh->login($user, $pass);
>
>
> $ssh->register_handler("stderr", sub {
> my($channel, $buffer) = @_;
> my $str = $buffer->bytes;
>
>
> if ($str eq "Enter login password: ") {
> $channel->send_data($old_password);
> }
>
>
> elsif ($str eq "New password: ") {
> $channel->send_data($new_password);
> }
>
> elsif ($str eq "Re-enter new password: ") {
> $channel->send_data($new_password);
> }
> });
> $ssh->cmd('passwd');
> ==========================================
>
> After running the program, my password didnt changed I was still able to
> connect using the old password.
>
> Does anybody has an idea what's missing or wrong with my script?
>
> Thanks.
>
> Jaws
which might eliminate typo's. Something like:
if ($str =~ /enter\s+login\s+password/i ) {
$channel->send_data($old_password);
}
elsif ($str =~ /new\s+password/i ) {
$channel->send_data($new_password);
}
elsif ($str =~ /re.enter\s+new\s+password/i ) {
$channel->send_data($new_password);
}
Cheers
--
Nico Coetzee
[url]http://www.itfirms.co.za/[/url]
[url]http://za.pm.org/[/url]
[url]http://forums.databasejournal.com/[/url]
To the systems programmer, users and applications serve only to provide a
test load.
Nico Coetzee Guest
-
Sharad Gupta #14
Net::SSH::Perl
Hi All,
I remember i read somewhere about some limitations of Net::SSH::Perl on
windows systems particularly something about 5.8
but can't find the link now.
Can anybody point me to it without much effort.??
Thanx,
-Sharad
Sharad Gupta Guest
-
Martin Sommer #15
Net::SSH::Perl
Hi,
i have a problem with the Net::SSH::Perl module. i'd like to code a ssh
client in perl, that needs no special functions. it only has to login
and stay there until disconnection. after that it should reconnect and
so on...
i won't enter any commands at the shell after login...it just has to
login and finito.
but:
with the perl ssh module it connects to the given server, but the login
process does not work, i always get a connection timeout.
where is my fault?
---
loginperl.pl
#!/usr/bin/perl
use Net::SSH::Perl;
my $host = 'my.nice.host';
my $user = 'username';
my $passwd = 'password';
my $ssh = Net::SSH::Perl->new($host, protocol => 2, debug => true);
$ssh->login($user,$passwd);
thx,
martin
Martin Sommer Guest




