#!/usr/bin/perl use warnings; use strict; use Net::SSH2; use Data::Dumper; my $hostname = shift; chomp($hostname); my $ssh2 = Net::SSH2->new(); $ssh2->connect($hostname) or die "cant connect to $hostname\n"; $ssh2->auth_password('root','mypassword') or die "cant login to $hostname\n"; (my $code, my $error_name, my $error_string) = $ssh2->error(); if ($code) { print "$code: $error_name: $error_string \n"; exit(); } my $chan = $ssh2->channel(); $chan->blocking(0); $chan->shell(); print $chan "uname -a\n"; my @uname = <$chan>; print @uname; print $chan "who\n"; my @who = <$chan>; print @who; $chan->close; #### [root@lpo-wiki-01 ~]# ./ssh.pl localhost Linux lpo-wiki-01 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux root pts/0 2008-05-15 07:54 (val.vmsinfo.com) root pts/1 2008-05-15 12:11 (val.vmsinfo.com) root pts/2 2008-05-18 11:42 (10.41.0.213) [root@lpo-wiki-01 ~]# ./ssh.pl yoda cant connect to yoda [root@lpo-wiki-01 ~]#