Difference between revisions of "Script Prototypes"

From Nuclear Physics Group Documentation Pages
Jump to navigationJump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
== setres ==
+
==Einstein/Lentil checkup==
Bash function for remotely setting ''/etc/resolv.conf'' to the proper values:
+
There are probably some other critical services that should be added to this list, although many are checked implicitly if the user can log into a non-einstein machine (LDAP, NFS).
<pre>function setres
+
<pre>#!/bin/bash
{
 
    home=~
 
    master="$home/bin/master_resolv.conf"
 
    scp $master root@$1:/etc/resolv.conf
 
}</pre>
 
Would be better if the function checked to see if the file didn't exist, and if not, created it.  Or maybe it would be better to have the "master" file on a specific machine.  Actually, even better would be a program that maps settings to files.
 
  
Here's a shot at it. Doesnt' check to see if it exists or not, but handles the copying and can play with as many different types of config files as we want. Just add to the hash table as necessary. Need to be able to login as root on destination machine from source machine.
+
ssh root@einstein "df -h; service spamassassin status; service amavisd status; service postfix status"
<pre>
+
ssh root@lentil "df -h /mnt/npg-daily-current"
#!/usr/bin/perl -w
 
#Matthew Minuti --last updated 7/20/07
 
# This is a program to push master config files to specific NPG machines.
 
 
 
# If no or one arguments given, print usage and exit.
 
if(not $ARGV[0] or not $ARGV[1]){
 
        print "\n Usage: replaceconfig.pl config host\n where config is a settings file and host is the host to check\n E.g. replaceconfig.pl resolv.conf improv  to act on improv's /etc/resolv.conf\n\n";
 
        exit;
 
}
 
 
 
# Defining scp for copying
 
my $scp="/usr/bin/scp";
 
 
 
# Set up a hash table so that we know where each config file master is, and
 
# where the copied file should end up.
 
my %settings = (
 
        "resolv.conf" => "/etc/resolv.conf /etc/resolv.conf.npgmaster",
 
        "nsswitch.conf" => "/etc/nsswitch.conf /etc/nsswitch.conf.npgmaster",
 
);
 
 
 
# See if we know about the passed config argument, and if not, whine and exit.
 
if(not $settings{$ARGV[0]}){
 
        print "\nSorry, $ARGV[0] isn't defined in the settings list. Bye!\n";
 
        exit;
 
}
 
 
 
# Find out what config file we're concerned with and format the locations
 
# appropriately.
 
my ($writeloc, $sourceloc) = split " ", $settings{$ARGV[0]};
 
 
 
# Set up another variable to avoid perl interpreting the .'s in filenames
 
# as concatenation
 
$scpargs = "$sourceloc $ARGV[1]:$writeloc";
 
 
 
# Send a copy of the master where it belongs!
 
`$scp $scpargs`;
 
</pre>
 
I've decided that using a hash table isn't as good a way to do it as I previously thought.  Doing it that way requires that both the source code and the files be modified when a configuration is added, and complicates the code.  Instead, master files should be kept in a known location (maybe ''/etc/npg-master'' or something).  The program will take a filename and host, and try to open and copy "master-''filename''" to some location on ''host''.  Something along these lines:
 
<pre>#!/usr/bin/perl -w
 
use strict;
 
#Steve McCoy
 
#  Program for pushing master config files to machines
 
 
 
sub masterloc($);
 
sub badloc($);
 
 
 
 
 
$ARGV[0] or die "need a filename\n";
 
$ARGV[1] or die "need a hostname\n";
 
 
 
my $master = masterloc($ARGV[0]);
 
my $bad = badloc($ARGV[0]);
 
 
 
my $scp = "/usr/bin/scp";
 
my $args = "$master $ARGV[1]:$bad";
 
 
 
`$scp $args`;
 
 
 
 
 
sub masterloc($)
 
{
 
    my $ml = "/etc/npg-master/$_[0]";
 
    -e $ml or die "no master file \"$ml\"\n";
 
    return $ml;
 
}
 
 
 
sub badloc($)
 
{
 
    return "/etc/$_[0]";
 
}
 
 
</pre>
 
</pre>

Latest revision as of 14:16, 15 February 2008

Einstein/Lentil checkup

There are probably some other critical services that should be added to this list, although many are checked implicitly if the user can log into a non-einstein machine (LDAP, NFS).

#!/bin/bash

ssh root@einstein "df -h; service spamassassin status; service amavisd status; service postfix status"
ssh root@lentil "df -h /mnt/npg-daily-current"