#!/usr/bin/perl # caution: this script logs into remote machine and execute commands. # for the script to work fine, the sshd on the remote machine must accept # password-based authentication. this is controlled with the parameter # "PasswordAuthentication yes" in sshd_config. use warnings; use strict; use Net::SSH::Perl; my $host = '192.168.100.21'; my $port = '22'; my $user = 'dummy'; my $pass = 'dummy'; my %config = ( port => $port, debug => 1, interactive => 0, options => ["ChallengeResponseAuthentication no"] ); my $ssh = Net::SSH::Perl->new($host, %config); $ssh->login($user, $pass); my ($out, $err, $exit) = $ssh->cmd("uname -a"); print "$out\n"; if ($out =~ /^Darwin/) { ($out, $err, $exit) = $ssh->cmd("sw_vers"); print "$out\n"; }