#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use constant { HOST => q{rocky}, USER => q{rocky}, KEYPATH => q{~/.ssh/broadey.net_rsa}, CMD => q{whoami}, }; #my $ssh = Net::OpenSSH->new(HOST); my $ssh = Net::OpenSSH->new(HOST, user=>USER, key_path=>KEYPATH); $ssh->error and die "Can't ssh to ${\HOST}: " . $ssh->error; my ($out,$pid) = $ssh->pipe_out(CMD) or die "Remote command failed: " . $ssh->error; local $| = 1; # enable output autoflush while (<$out>) { print time, ": ", $_; # $_ includes the \n }