Multiple server find and replace

J

jdonovan151

So I have about 70-80 servers that have a Nagios check running on
them.. I realized today that in one of the .cfg files there is a
value that is "/nagios/plugins/check_disk -w 20 -c 10"
it needs to read:
/nagios/plugins/check_disk -w 20% -c 10%

I have the server list in a text file and can ssh as root to all of
these servers what I need to be able to do is have a script that will
read in the server list then go out to each machine go to /usr/local/
nagios/myfile.cfg
find that line and replace the value of 20 with the value of 20%.

Any help is much appreciated and if your in the Boston area might get
you a beer or two :)

Thanks !
 
C

C.DeRykus

So I have about 70-80 servers that have a Nagios check running on
them..  I realized today that in one of the .cfg files there is a
value that is "/nagios/plugins/check_disk -w 20 -c 10"
it needs to read:
/nagios/plugins/check_disk -w 20% -c 10%

I have the server list in a text file and can ssh as root to all of
these servers what I need to be able to do is have a script that will
read in the server list then go out to each machine go to /usr/local/
nagios/myfile.cfg
find that line and replace the value of 20 with the value of 20%.

If the servers have Perl, here's some untested
code to get you started:


open the list of servers
loop/read through server list:
0 == system( "ssh server_name
q{ perl -pi.bak -e 's/xxx/%20 -c 10%/' config }" )
or die "server_name config fixup failed: $?";
end of loop
 
C

C.DeRykus

...
open the list of servers
loop/read through server list:
   0 == system( "ssh server_name
      q{ perl -pi.bak -e 's/xxx/%20 -c 10%/' config }" )
   or die "server_name config fixup failed: $?";

I meant it when I said "untested":

That should be something more like:

system( "ssh server_name "
. q{ perl -pi.bak -e '...' } config )"
or die ...

Any further errors are an exercise for the reader :)
 
M

Marc Girod

system( "ssh server_name "
          . q{ perl -pi.bak -e '...' } config )"
   or die ...
Any further errors are an exercise for the reader :)

Now, there's an odd number of double quotes in my count,
so:

system( "ssh server_name "
. q{ perl -pi.bak -e '...' config )

Do any of you use either of Net::SSH::perl or Net::SSH2,
or any other ssh perl client, instead of resorting to
system and the command line ssh?

Where you able to install it on Windows (for use by
people not installing cygwin)?
How?...
I am stuck in gmp and Math::GMP / Math::pari depending on
it. I have tried building gmp-4.3.1 from sources, which
requires a shell understanding ./configure, and thus msys
on MinGW...) as well as downloading 4.2 binaries.
I'd wish for a path with a known light at the end of the
tunnel...

Thanks,
Marc
 
C

C.DeRykus

Now, there's an odd number of double quotes in my count,
so:

system( "ssh server_name "
       . q{ perl -pi.bak -e '...' config )

Thanks, I think the brace and paren were swapped too:

system( "ssh server_name "
. q{ perl -pi.bak -e '...' config } )
Neither of Net::SSH::perl or Net::SSH2,
or any other ssh perl client, instead of resorting to
system and the command line ssh?

Where you able to install it on Windows (for use by
people not installing cygwin)?
How?...
I am stuck in gmp and Math::GMP / Math::pari depending on
it. I have tried building gmp-4.3.1 from sources, which
requires a shell understanding ./configure, and thus msys
on MinGW...) as well as downloading 4.2 binaries.
I'd wish for a path with a known light at the end of the
tunnel...

This is the really hard area. I've built and installed (with
difficulty) on Unix but the build failed for me on Strawberry Perl.
Also tried a pre-built 5.10 from theory5:

ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/Net-SSH-Perl.ppd
ppm install failed: Can't find any package that provides Crypt-DH for
Net-SSH-Perl
Can't find any package that provides Crypt-IDEA for Net-SSH-Perl
Can't find any package that provides Math-Pari for Net-SSH-Perl
Can't find any package that provides Crypt-RSA for Net-SSH-Perl
Can't find any package that provides Math-GMP for Net-SSH-Perl
Can't find any package that provides Crypt-DSA for Net-SSH-Perl

Maybe someone's had more luck... or possibly the 5.6/5.8 pre-built's
are more tractable.

(redirected to comp.lang.perl.modules)
 
T

Ted Zlatanov

jc> So I have about 70-80 servers that have a Nagios check running on
jc> them.. I realized today that in one of the .cfg files there is a
jc> value that is "/nagios/plugins/check_disk -w 20 -c 10"
jc> it needs to read:
jc> /nagios/plugins/check_disk -w 20% -c 10%

jc> I have the server list in a text file and can ssh as root to all of
jc> these servers what I need to be able to do is have a script that will
jc> read in the server list then go out to each machine go to /usr/local/
jc> nagios/myfile.cfg
jc> find that line and replace the value of 20 with the value of 20%.

jc> Any help is much appreciated and if your in the Boston area might get
jc> you a beer or two :)

Rather than screwing around with quoting, do this:

1) put the commands in a local file
2) copy the file to the remote system into, say, /tmp/go.sh
3) run "ssh MACHINE /tmp/go.sh"

This is significantly simpler, faster to develop, easier to understand
and trace (you can name the remote file with the date and time of
execution, so you know who ran what). Plus you won't have any quoting
bugs.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top