Harold Castro wrote:
Good day!

Hello,


I'm new to perl but not that much of a newbie. In
fact I was in the peak of learning perl but then I
have to focus my concentration with work when I got my
first job. I will be a trainee for 3 months and my
first assignment is to administer our squid
proxies(4). I line with this, the work target form includes a
step in which I would have to learn how to update
every config files of squid automatically, meaning, if
my boss updates a squid config on one machine, changes
will also be applied on other squid proxies not to
mention telling them also to run 'squid -k reconfig'
to reflect the changes.


I need a hint on how I will going to accomplish this
using perl. Perhaps a program sitting on every proxy
machine and then another program which will tell that
program regarding the squid config changes and the
first program will issue a line like 'open SQUID,
"/usr/local/squid/sbin/squid -k reconfig |" upon
hearing the advertisement from the second program.


What do you think? Do you know another better way to do it? Any insight about the concept or the modules I can use, if theres any..

Can you do it via SSH?

If so look on search.cpan.org for Net::SSH
 (http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm)

Sytax wise this code is ok but it is untested.
It should give you a start :)

#!/usr/bin/perl

use strict;
use warnings;
use Net::SSH qw(ssh);

my $localconf = '/usr/local/squid.conf';
my $resquid = 'squid -k reconfig';

my %sync = (
 'Label 1' => {
    user => '[EMAIL PROTECTED]',
    command => ['scp [EMAIL PROTECTED]:$localconf $localconf',$resquid]
 },
 'Label 2' => {
    user => '[EMAIL PROTECTED]',
    command => ['scp [EMAIL PROTECTED]:$localconf $localconf',$resquid]
 }
);

for my $l(keys %sync) {
   print "Staring $l...\n";
   for(@{ $sync{$l}->{command} }) {
      ssh($sync{$l}->{user},$_);
   }
   print "Done\n";
}


Then just execute it when /usr/local/squid.conf is updated an voila all good :)


You could always improve it, add error handling for ssh() so you knwo what its doing, create %sync based on a database, etc...

HTH

Lee.M - JupiterHost.Net

--
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