#!/usr/bin/perl use strict; use Net::SSH::Perl; my $host = '172.16.9.40'; my $username = 'power'; my $ssh = Net::SSH::Perl->new($host,$username,options =>["interactive yes","identity_files $ENV{HOME}/.ssh/id_dsa"]); $ssh->login($username); my $cmd; #my $cmd="sudo aptitude update"; if ($cmd) { my($out, $err, $exit) = $ssh->cmd($cmd); print $out if $out; print $err if $err; } else { eval "use Term::ReadKey;"; ReadMode('raw'); eval "END { ReadMode('restore') };"; $ssh->shell; print "Connection to $host closed.\n"; }