#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Tk; my $mw = MainWindow->new; my $text = $mw->Text(); $text->pack; $text->insert('end',"Net::SSH::Perl Test\n"); $mw->Button( -text => "SSH", -command => \&do_ssh )->pack; $mw->Button( -text => "Exit", -command => sub{exit} )->pack; MainLoop; sub do_ssh{ my $user = "z"; my $password = "ztest"; my @hosts = qw(localhost); foreach my $host (@hosts){ my $cmd = "/usr/bin/uptime"; my $ssh = Net::SSH::Perl->new( $host, port => 22 , protocol => 2, # debug => 1, ); $ssh->login($user,$password); my($out) = $ssh->cmd($cmd); my ($time,$uptime) = (split /\s+/,$out)[1,3]; chop $uptime; $text->insert('end', "$out\n"); $text->insert('end', "$host has been up $uptime\n"); } }