I have a script that I use to ssh to a list of servers to run a few
commands. I'm trying to find a way su up & run a command - however I'm
in need of some inspiration as to how to pull this off.

Heres the script template for reference:-

#!/usr/bin/perl -w

use strict;
use Term::ReadKey;
use  Net::SSH::Perl;

my $cmd1 = 'uname -a';

# Get user/pass for session
print "Enter your username for this session: ";
chomp(my $user = <STDIN>);
print "And your password: ";
ReadMode('noecho');
chomp(my $passwd = ReadLine(0));
ReadMode('restore');
print "\n";

while ( <DATA> ) {
   chomp $_;
   my $host = $_;
   my $ssh = Net::SSH::Perl->new($_, 2,1);
   $ssh->login($user, $passwd);
   my($stdout, $stderr, $exit) = $ssh->cmd($cmd1);
   
   <insert expect inspiration here>

   my $out = $stdout;
   print "$out\n";
}
__DATA__
host1
host2
host3

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to