CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Help required in refining a script!!!: Edit Log



UnixAAP
Novice

Mar 25, 2014, 3:13 AM


Views: 18269
Help required in refining a script!!!

Hi Perl Gurus.,

I am a system admin & new to perl scripting..

I need help to create a program to run command on multiple servers (50) .

Login to servers with SSH & encryption key.

I have created a txt file with IP addresses(50) of those servers.= hostlist.txt

This is the command I want to run

command1= esxcli system syslog config set --loghost='udp://<IP address>:514

command2= esxcli system syslog reload



I referred to several other websites & tried to create a dummy script dunno if it works!!



Code
#!/usr/bin/perl 

use strict;
use Net::OpenSSH;

my $ssh;
my $host;
my $start;
my $password;

print "Password: ";
system('stty','-echo');
chop($password=<STDIN>);
system('stty','echo');
print "\n";
open (HOST,"input.txt");
while (<HOST>){
if(/\d+\.\d+\.\d+\.\d+/) {
chomp;
$host = $_;
} else {
print "input.txt must list hosts in IPv4 format.\n";
next;
}
print "Adding files to $host";
$ssh = Net::OpenSSH->new("root:$password\@$host");
$ssh->error and
die "Couldn't establish SSH connection: ". $ssh->error;
$ssh->system = ("esxcli system syslog config set --loghost='udp://<IP address>:514' && esxcli system syslog reload");



Any help on this would be of gr8 help!! :-)


(This post was edited by FishMonger on Mar 25, 2014, 6:52 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Mar 25, 2014, 6:52 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives