Okay, it is still super rough, and I haven't put in any error trapping, but I got the following to work:
#!/usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
print "Enter user name: ";
my $user = <STDIN>;
chomp $user;
print "Enter password: ";
my $password = <STDIN>;
chomp $password;
print "Enter domain :";
my $domain = <STDIN>;
chomp $domain;
my @hosts = `host -l $domain |cut -d " " -f 1`;
foreach my $host (@hosts) {
chomp $host;
print "Accessing $host... \n";
my $ssh = Net::OpenSSH->new($host, user => $user, password => $pas
+sword, strict_mode => 0, timeout => 1, master_opts => [-o => "Stric
+tHostKeyChecking=no"]);
$ssh->error and warn "ssh failed on $host : " . $ssh->error;
my $test = $ssh->system('sudo crontab -u foouser -l');
}
Any ideas to make it more elegant/efficient, etc. would be much appreciated. I am *very* rusty with Perl these days...
Code tags added by GrandFather
|