Cover V12, I09

Article
Listing 1
Listing 2a
Listing 2b
Listing 3
Listing 4
Listing 5
Listing 6

sep2003.tar

Listing 6 rcndupdt script

#!/usr/bin/perl
###############################################################
######## Name: rcndupd
########
######## Purpose: To update /appscripts on all nodes from /u/shared/appscripts
######## For runlevel and rccfg checks
########
######## Author: BJM 5/29/02
######## BJM 5/31/02 Added mk cp of key in /tmp
###############################################################
use strict;
### Globals ###########
### Config file Parms
my $gscripts; my $lscripts; my $rclog; my $stlink; my $stplink; my $secaccess;
### Go read config file and parms
read_cfg();
my $ldir="$lscripts/" ;
my $gdir="$gscripts/" ;
#########################################
### Go read config file and parms
my @flist=(); my %startlst=(); my @tmp=();
### Globals ###########
################################# MAIN -------
mklst();
cpfiles();
###############################################################
sub cpfiles {
#local var
my $key; my $lstamp; my $gstamp;my $mtime; my $ctime;
my $lfile; my $gfile; my $comm; my $tlfile;
print " Starting Copy function for Local Runlevel scripts \n";
foreach $key ( sort keys %startlst) {
$lfile="$ldir$key";
$gfile="$gdir$startlst{$key}";
#print "-$lfile- and -$gfile- \:File names \n";
$mtime = (stat $lfile)[9]; $lstamp=$mtime;
$mtime = (stat $gfile)[9]; $gstamp=$mtime;
if ($gstamp > $lstamp) {
print "\tGlobal is newer Gtime\=$gstamp
Ltime\=$lstamp\n";
print " \t\t$key \-\>$startlst{$key} \n";
$tlfile="/tmp/$key.sav" ;
$comm="cp -p $lfile $tlfile ";
system("$comm");
$comm="cp -p $gfile $lfile";
system("$comm");
print "\t\t\t Copying \-\-$comm \n" ;
} else { print "\tGlobal and Local in sync for $lfile \n"; }
$gstamp=0; $lstamp=0;
}
print " Ending Copy function for Local Runlevel scripts \n";
}
###############################################################
sub mklst {
#local var
my $key; my $comm; my $gname;
# make hash and file list
$comm="ls $ldir | grep -E \"^S\"" ;
open(fin,"$comm |");
while (<fin>) {
chomp();
push(@flist,$_);
@tmp=split(/\./,$_);
shift(@tmp);
$gname=join("\.",@tmp);
$startlst{$_}="$gname";
}
print " Starting list of Local Runlevel Scripts \n";
foreach $key ( sort keys %startlst) {
print " \t\t $key \-\>$startlst{$key} \n";
}
print " Ending List list of Local Runlevel Scripts \n\n";
}
###############################################################
sub read_cfg {
#Global variables
#my $gscripts; my $lscripts; my $stlink; my $stplink; \
my $rclog;my $secaccess;
##########################Local Vars
my $match="gscripts lscripts stlink stplink rclog"; \
## required parm list
my @mlist=split(" ",$match);
my @line; my %rparm; my $key; my $parm;
my $config_file="/etc/rccfg.config";
###########################################3
open(fin,"cat $config_file \| grep -vE \"^\\#\" |") || die \
" Config file $config_file is not present -- \n";
## Read config into hash
while (<fin>) {
chomp;
if ((/[a-z]/i)) { # Allow for blanks
@line=split(/ /);
if ($match =~/$line[0]/) {
$rparm{$line[0]}=$line[1];
}
}
}
close(fin);
####Setting Parms
for $key (keys %rparm) {
#print " $key -> $rparm{$key} \n";
if ($key eq "gscripts") {$gscripts=$rparm{$key}; }
elsif ($key eq "lscripts") {$lscripts=$rparm{$key}; }
elsif ($key eq "secaccess") {$secaccess=$rparm{$key}; }
elsif ($key eq "stlink") {$stlink=$rparm{$key}; }
elsif ($key eq "stplink") {$stplink=$rparm{$key}; }
elsif ($key eq "rclog") {$rclog=$rparm{$key}; }
else { print " Invalid parm in config file $key ignored \n"; }
}
#####checking for all config variables
foreach $parm (@mlist) {
if ($rparm{$parm} =~/[a-z]/i) {
#print " $parm -> $rparm{$parm} is valid \n ";
} else { die "ERROR $parm is not valid and is required \
in rccfg.config file ERROR";}
}
}
### end sub read_cfg
########################################################################