#!/usr/bin/perl use Getopt::Long; use Net::SFTP::Foreign; use XML::Simple; use Net::OpenSSH; my $config = XMLin('agama.xml'); my $debug = 0; my $username = ''; my $password = ''; GetOptions ('debug' => \$debug, 'file=s' => \$rpmfile, 'username=s' => \$username, 'password=s' => \$password); foreach $host (@{$config->{hostname}}) { if ($password eq '') { $ssh = Net::OpenSSH->new($host,user=>$username,timeout => 10,strict_mode => 0); } else { $ssh = Net::OpenSSH->new($host,user=>$username,password=>$password,timeout => 10,strict_mode => 0); } $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; my $cmd1 = 'cd /usr/local/ ; ls -la'; my $cmd2 = 'ls -la'; print "Output cmd1:\n"; $ssh->system($cmd1) or die "remote command failed: " . $ssh->error; print "Output cmd2:\n"; $ssh->system($cmd2) or die "remote command failed: " . $ssh->error; }