Listing 2b  Example of Global and Local Directories

Control Workstation 
		 /u/shared/appscripts 
		 		 tsm.ob
		 		 ssl.ir 
		 		 csmf.sparky 
		 		 date.all 
		 		 ctsload.fritz 
		 		 db2.all 

Node - Sparky 
		 /appscripts 
		 		 S01.csmf.sparky
		 		 S02.date.all 
		 		 S02.ssl.ir 

Node - fritz 
		 /appscripts 
		 		 S01.ctsload.fritz
		 		 S02.date.all 
		 		 S02.tsm.ob 
Node - Iris 
		 /appscripts 
		 		 S01.date.all 
		 		 S99.date.all 


Node - lizard 
		 /beavis  
		 		 S01.date.all 
		 		 S03.tsm.ob 
		 		 S10.db2.all 


#!/usr/bin/perl    
#############################################################
##### file name: rccfg
##### purpose:		 Runlevel tool used my sys admin to manage runlevel rc scripts 
#####		  		 secured version 1.3 		 
#####
##### author: BJM 01/06/03
#############################################################
use strict;  use File::Basename; 
##################Global Vars #########################
################# Config File #########################
my $gscripts; my $lscripts; my $stlink; my $stplink; my $rclog; my $secaccess; 
read_cfg(); ### Go read config file and get parms 
my $command=basename($0); chomp($command); 
my $secfile="$secaccess/$command.access"; 
################# Config File #########################

my $host=`hostname -s ` ; chomp($host); 
my $ldate=`date +%m_%y`; chomp($ldate);
my $rccfglog="$rclog/rccfglog.$ldate"; ## command log file  
my @srchlist=(); ## Global link name 
my $parms=join("",@ARGV);
my $comn; my $appn; 
my $valid="start stop list all status build noauto"; 
my $appaccess; ## for use with secured ver filled from /etc/<basename>.access 
################## End Global Vars #########################

######################### MAIN 
chk_input(); 		 		          		 ### chk input parms 
if ( $comn=~/build/ix ) { bld_links();}		 ### Create links  
elsif  ($comn=~/noauto/ix) { 
		 noauto("$stlink");
		 noauto("$stplink"); } 		 		 ### remove links 
elsif ($comn eq "list") {list_apps();}  ### List All Applications  
else { rc_std(); } 		 		 		 ### start,stop,status calls 
############################ MAIN 

############################################################
sub rc_std {
		 ### Mimic Standard rc 
		 ### local Vars
                my $comm; my $item; 
        ### local Vars
		 ## load list of scripts into array of srchlist
		 if ($appn eq "All") { mappn("All") ; ## Load all scripts 
		 } else { mappn("$appn"); }		      ## Load specific script 
		 ####################################### send task to script list 
		 while(@srchlist) { 
		 		 $item=shift(@srchlist); 
		 		 $comm="$stlink\/$item $comn"; 
		 		 print "$comm echo \n"; 
		 		 system("$comm"); 
		 }
}
############################################################
sub rm_links { 
		 ### To Remove lnks
		 ### local Vars
		 		 my @line=();  my $comm; my $file;  
		 		 my $target=$_[0]; 
        ### local Vars
#		 if (!($target=~/\//)) { die "you did not submit a removal directory ";}
		 ## remove all links prior to rebuild 
  		 opendir( lstdir, $target);
       		 while( defined ($file = readdir lstdir)) {
		 		 if (($file=~/^S/) || ($file=~/^K/)){ 
		 		 		 $comm=" rm $target\/$file ";
		 		 		 print " Removing $comm \n"; 
		 		 		 system("$comm"); 
		 		 }
		 }
		 close(lstdir); 
}
############################################################
sub list_apps { 
		 ### To list all Application Names 
		 ### local Vars
		 my @applist; my @appname; my $temp; 
		 ### local Vars
		 mappn("All"); ## go get all link names 
		 @applist=@srchlist; # filled by mappn
		 print "Runlevel Application Listing for Node $host \n"; 
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-";
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n";
		 while(@applist){ 
		 		 $temp=pop(@applist);  
		 		 @appname=split(/\./,$temp); 
		 		 print "     Application \-\> $appname[1] \n"; 
		 }
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-";
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n";
		 		 
} 
############################################################
sub bld_links { 
		 ### remove and recreate links in $stlink and $stplink 
		 ### local Vars
		 		 my $startlnk; my $stoplnk; 
		 		 my @line=();  my $comm; my $file;  
		 		 my $torder; my @korder;
        ### local Vars
		 ## remove all links prior to rebuild 
		 rm_links("$stlink"); 
		 rm_links("$stplink"); 
		 ## remove all links prior to rebuild 
		 opendir(lstdir,$lscripts) || die " cant open local directory ";
        while(defined ($file = readdir lstdir)) {
                if ($file=~/^S/){
                        @line=split(/\./,$file);
                        $startlnk="$stlink\/$line[0].$line[1].$line[2]";
                        print " making Start Link ln -s $lscripts\/$file  $startlnk\n";
                        system("ln -s $lscripts\/$file  $startlnk");
                        $torder=substr($file,1,2);
                        push(@korder,$torder); 
                }
        }
        close(lstdir);
        opendir(lstdir,$lscripts) || die " cant open local directory ";
        while(defined ($file = readdir lstdir)) {
                if ($file=~/^S/){
                        @line=split(/\./,$file);
                        $torder=pop(@korder); 
                        $stoplnk="$stplink\/K$torder.$line[1].$line[2]";
                        print " making Stop Link ln -s $lscripts\/$file  $stoplnk\n";
                        system("ln -s $lscripts\/$file  $stoplnk");
                }
        }
        close(lstdir);
		 print " Finished Removing/Restoring runlevel Links \n"; 
}
############################################################
sub noauto { 
		 ### remove start link 
		 ### local Vars
		 my $comm; my $file;  
		 		 my $lnkdir=$_[0];   
        ### local Vars
		 if (!($lnkdir =~ /\//)) { die " sent invalid dir to noauto " } 
		 ## Removing one or all links for an application 
		  opendir(lstdir,$lnkdir);
       		  while( defined ($file = readdir lstdir)) {
		 		 if(($appn=~/All/m)  && (($file=~/^K/)||($file=~/^S/))) { 
		 		 		 ## removing all links .. 
		 		 		 $comm="$lnkdir\/$file"; 
		 		 		 print " Removing all Startup links $comm \n"; 
		 		 		 system("rm $comm");
		 		 } else { 
		 		 		 #starting search 
		     		 		 if (($file=~/$lnkdir\/S/ix ) || ($file=~/\.$appn\./m )) { 
		 		 		 ### checking that its the start script 
		 		 		 $comm="$lnkdir\/$file"; 
		 		 		 print "Removing Startup link $comm \n"; 
                        system("rm $comm");
		 		 		 }  
		 		 }
		 }
		 close(lstdir); 
}
############################################################
sub mappn {  
		 ### Match App Name called to push filelist on Array from Search strings 
		 ### local Vars
        my $comm; my $match=$_[0]; my $file;  my $patt;
		 my @tmplist=(); 
        ### local Vars
        opendir( lstdir, $stlink ) || die " Failed to lstdir $stlink "; 
        while( defined ($file = readdir lstdir)) {
		 		 chomp; 
                if (( $file=~/^S/x) && ( $file=~/\.$match\./x) ){
		 		 		 push(@tmplist,$file);  
                } elsif (( $match eq "All" ) &&  ( $file=~/^S/) ){ 
		 		 		 push(@tmplist,$file);  
		 		 }
        }
		 ## Check to make sure we found a start script  
		 $patt=join('',@tmplist); 
		 if (!($patt=~/S/)) {print "\n\n Failed to Match an Application Name\n"; die Usage();} 
		 ## create ordered srchlist for return 
		 @srchlist= sort @tmplist ; 
}
############################################################
sub chk_input {  
		 ### local Vars ###########################3 
		 my $date=`date +%D-%T`; chomp($date); 
		 my $host=`hostname -s ` ; chomp($host); 
		 my $report="$date $0 @ARGV"; 
		 ### local Vars ###########################3 
		 ## If list is not in $parms then normal parm check
		 if ( $parms !~/list/i) {  
		 		 ## Check for command parms #'s then validity 
		 		 if ((!($ARGV[0])) || (!($ARGV[1])) || ($parms=~/\-h/x) || ($parms=~/all/x) || ($parms=~/\?/x )) { die Usage(); } 
		 		 ## Check for command parms
		 		 if  ( (!($valid =~/$ARGV[0]/x)) && (!($valid =~/$ARGV[1]/x)) ){ die Usage(); } 
		 		 ## set the command name and app name parm ## 
		 		 if ( $valid =~/$ARGV[0]/x ) { $comn =$ARGV[0]; $appn=$ARGV[1];}  
		 		 else {  $comn=$ARGV[1] ; $appn=$ARGV[0]; } 
		 		 if(($comn=~/build/m) && ( $appn !~/All/)) { die Usage(); } ## make sure they want to rebuild
		 } else { $comn="list"; $appn="All"; } 

		 ########### Security Access Check #######################################
		 if ($0 !~/rccfg/) { 
		 		 ### Read in security file if neccesary 
		 		 rsecfile("$secfile");
        		 if( ($appaccess !~/$appn/) && ($comn !~/status/) )  { 
                		 $report="$date $0 @ARGV  FAILED FOR ACCESS AND LOGGED " ;
                		 record("$report"); 
                		 die &Usage("F"); ## send die access msg
        		 } 
		 }
		 ########### Passed Access Check #######################################
		 ## Passed check log the command send to rccfg in /stats/hostname 
		 record("$report"); 
} 
############################################################
sub rsecfile { 
		 ## Security sub used for secured version only 
		 ##local Var 
		 my $fname="$_[0]"; chomp($fname); 
		 my @temp; 
		 ##local Var 
		 open(fin,$fname) || die " Secured Application Authorization file $fname does not exits \n";  
		 while (<fin>)  { 
		 		 if (!(/^\#/)) { 
		 		 		 @temp=split; 
		 		 		 $appaccess="$appaccess $temp[0] "; 
		 		 } 
		 } 
		 close(fin); 
} 
############################################################
sub Usage {
		 ### generic Usage for secured and unsecured version 
		 ###localVar 
		 		 my $secure; 
		 		 my $access; 
		 		 if ($_[0]) { 
		 		 		 $access="$_[0]"; ## should be "F"  
		 		 } else {  $access="T";} 
		 ###localVar 
		 ##Check if this is a secured version or not 
		  if  ($0 !~ /rccfg/ )  { 
		 		 $secure="T" 
		 } 
		 system("clear"); 
        print <<EOF ;
*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
EOF
		 if (($secure eq "T") && ($access eq "F" )) { 
		 		 print "UNAUTHORIZED APPLICATION ACCESS --\n"; 
		 } 
        print <<EOF ;
        $0  <app name > < command > 
		 $0  <command> <appname> 
		 		 Valid commands: 
		 		 		 start  <appname> = Call link for appname startup 
		 		 		 stop   <appname> = Call link for appname stop 
		 		 		 status <appname> = Call link for appname status 
		 		 		 noauto <appname> = Remove startup link for an application
		 		 		 noauto <appname> = Remove startup link for an application
		 		 		 build  All 		  = Refresh/Recreate all Runlevel links from local dir
		 		 		 		 		    The "All" appname is req and case sensitive 
		 		 		 list 		 		  = Lists all local Runlevel Application Names 

		 		 Valid appnames 
EOF
		 if ($secure eq "T" ) {  
		 		 print "$appaccess "; 
		 } else { 
        print <<EOF ;
		 		       <appname> = Pattern to match <full field will be matched, case sensitive >
		 		             All = Run the command for all, case sensitive 
EOF
		 }  
		 if (($secure) && ($access eq "F" )) { 
		 		 print "\n\n---UNAUTHORIZED APPLICATION ACCESS WAS RECORDED----\n"; 
		 } 
        print <<EOF ;

*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
EOF
exit;
}
###########################################################
sub record {
		 ### record valid commands to log file 
        ### local Vars ###########################3
        my $msg=$_[0];
		 #$rclog is our log file 
        if (!( -d ("$rclog"))) { die "$rclog does not exist ABORT";
exit :}
        open(record,">>$rccfglog");
        print record "$msg \n";
        close(record);
}
############################################################
############################################################33
sub read_cfg  { 
		 # Read in Global variables 
		 #my $gscripts; my $stlink; my $stplink; my $rclog; my $lscripts; my $secaccess; 
		 ##########################Local Vars 
		 my $match="gscripts lscripts stlink stplink rclog secaccess "; ## 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
############################################################
#<appname> # comment 
armgr  ## archive Manager 
db2		 ## db2 startup scripts 
mmgr_ftb ## Media Manager 
mmgr_jpm ## Media Manager JP Morgan 
mmgr_bac ## Bank of america MMgr 
tiff 
ondemand_obj
ondemand_obj_vp02
ondemand_obj_vp03 
ondemand_lb 
ondemand_lb_vp02 
ondemand_lb_vp03
ondemand_lb_vp02t 
ondemand_lb_vp03t 
armgr 
#!/usr/bin/perl    
#############################################################
##### file name: rccfg
##### purpose:		 Runlevel tool used my sys admin to manage runlevel rc scripts 
#####		  		 secured version 1.3 		 
#####
##### author: BJM 01/06/03
#############################################################
use strict;  use File::Basename; 
##################Global Vars #########################
################# Config File #########################
my $gscripts; my $lscripts; my $stlink; my $stplink; my $rclog; my $secaccess; 
read_cfg(); ### Go read config file and get parms 
my $command=basename($0); chomp($command); 
my $secfile="$secaccess/$command.access"; 
################# Config File #########################

my $host=`hostname -s ` ; chomp($host); 
my $ldate=`date +%m_%y`; chomp($ldate);
my $rccfglog="$rclog/rccfglog.$ldate"; ## command log file  
my @srchlist=(); ## Global link name 
my $parms=join("",@ARGV);
my $comn; my $appn; 
my $valid="start stop list all status build noauto"; 
my $appaccess; ## for use with secured ver filled from /etc/<basename>.access 
################## End Global Vars #########################

######################### MAIN 
chk_input(); 		 		          		 ### chk input parms 
if ( $comn=~/build/ix ) { bld_links();}		 ### Create links  
elsif  ($comn=~/noauto/ix) { 
		 noauto("$stlink");
		 noauto("$stplink"); } 		 		 ### remove links 
elsif ($comn eq "list") {list_apps();}  ### List All Applications  
else { rc_std(); } 		 		 		 ### start,stop,status calls 
############################ MAIN 

############################################################
sub rc_std {
		 ### Mimic Standard rc 
		 ### local Vars
                my $comm; my $item; 
        ### local Vars
		 ## load list of scripts into array of srchlist
		 if ($appn eq "All") { mappn("All") ; ## Load all scripts 
		 } else { mappn("$appn"); }		      ## Load specific script 
		 ####################################### send task to script list 
		 while(@srchlist) { 
		 		 $item=shift(@srchlist); 
		 		 $comm="$stlink\/$item $comn"; 
		 		 print "$comm echo \n"; 
		 		 system("$comm"); 
		 }
}
############################################################
sub rm_links { 
		 ### To Remove lnks
		 ### local Vars
		 		 my @line=();  my $comm; my $file;  
		 		 my $target=$_[0]; 
        ### local Vars
#		 if (!($target=~/\//)) { die "you did not submit a removal directory ";}
		 ## remove all links prior to rebuild 
  		 opendir( lstdir, $target);
       		 while( defined ($file = readdir lstdir)) {
		 		 if (($file=~/^S/) || ($file=~/^K/)){ 
		 		 		 $comm=" rm $target\/$file ";
		 		 		 print " Removing $comm \n"; 
		 		 		 system("$comm"); 
		 		 }
		 }
		 close(lstdir); 
}
############################################################
sub list_apps { 
		 ### To list all Application Names 
		 ### local Vars
		 my @applist; my @appname; my $temp; 
		 ### local Vars
		 mappn("All"); ## go get all link names 
		 @applist=@srchlist; # filled by mappn
		 print "Runlevel Application Listing for Node $host \n"; 
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-";
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n";
		 while(@applist){ 
		 		 $temp=pop(@applist);  
		 		 @appname=split(/\./,$temp); 
		 		 print "     Application \-\> $appname[1] \n"; 
		 }
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-";
		 print "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n";
		 		 
} 
############################################################
sub bld_links { 
		 ### remove and recreate links in $stlink and $stplink 
		 ### local Vars
		 		 my $startlnk; my $stoplnk; 
		 		 my @line=();  my $comm; my $file;  
		 		 my $torder; my @korder;
        ### local Vars
		 ## remove all links prior to rebuild 
		 rm_links("$stlink"); 
		 rm_links("$stplink"); 
		 ## remove all links prior to rebuild 
		 opendir(lstdir,$lscripts) || die " cant open local directory ";
        while(defined ($file = readdir lstdir)) {
                if ($file=~/^S/){
                        @line=split(/\./,$file);
                        $startlnk="$stlink\/$line[0].$line[1].$line[2]";
                        print " making Start Link ln -s $lscripts\/$file  $startlnk\n";
                        system("ln -s $lscripts\/$file  $startlnk");
                        $torder=substr($file,1,2);
                        push(@korder,$torder); 
                }
        }
        close(lstdir);
        opendir(lstdir,$lscripts) || die " cant open local directory ";
        while(defined ($file = readdir lstdir)) {
                if ($file=~/^S/){
                        @line=split(/\./,$file);
                        $torder=pop(@korder); 
                        $stoplnk="$stplink\/K$torder.$line[1].$line[2]";
                        print " making Stop Link ln -s $lscripts\/$file  $stoplnk\n";
                        system("ln -s $lscripts\/$file  $stoplnk");
                }
        }
        close(lstdir);
		 print " Finished Removing/Restoring runlevel Links \n"; 
}
############################################################
sub noauto { 
		 ### remove start link 
		 ### local Vars
		 my $comm; my $file;  
		 		 my $lnkdir=$_[0];   
        ### local Vars
		 if (!($lnkdir =~ /\//)) { die " sent invalid dir to noauto " } 
		 ## Removing one or all links for an application 
		  opendir(lstdir,$lnkdir);
       		  while( defined ($file = readdir lstdir)) {
		 		 if(($appn=~/All/m)  && (($file=~/^K/)||($file=~/^S/))) { 
		 		 		 ## removing all links .. 
		 		 		 $comm="$lnkdir\/$file"; 
		 		 		 print " Removing all Startup links $comm \n"; 
		 		 		 system("rm $comm");
		 		 } else { 
		 		 		 #starting search 
		     		 		 if (($file=~/$lnkdir\/S/ix ) || ($file=~/\.$appn\./m )) { 
		 		 		 ### checking that its the start script 
		 		 		 $comm="$lnkdir\/$file"; 
		 		 		 print "Removing Startup link $comm \n"; 
                        system("rm $comm");
		 		 		 }  
		 		 }
		 }
		 close(lstdir); 
}
############################################################
sub mappn {  
		 ### Match App Name called to push filelist on Array from Search strings 
		 ### local Vars
        my $comm; my $match=$_[0]; my $file;  my $patt;
		 my @tmplist=(); 
        ### local Vars
        opendir( lstdir, $stlink ) || die " Failed to lstdir $stlink "; 
        while( defined ($file = readdir lstdir)) {
		 		 chomp; 
                if (( $file=~/^S/x) && ( $file=~/\.$match\./x) ){
		 		 		 push(@tmplist,$file);  
                } elsif (( $match eq "All" ) &&  ( $file=~/^S/) ){ 
		 		 		 push(@tmplist,$file);  
		 		 }
        }
		 ## Check to make sure we found a start script  
		 $patt=join('',@tmplist); 
		 if (!($patt=~/S/)) {print "\n\n Failed to Match an Application Name\n"; die Usage();} 
		 ## create ordered srchlist for return 
		 @srchlist= sort @tmplist ; 
}
############################################################
sub chk_input {  
		 ### local Vars ###########################3 
		 my $date=`date +%D-%T`; chomp($date); 
		 my $host=`hostname -s ` ; chomp($host); 
		 my $report="$date $0 @ARGV"; 
		 ### local Vars ###########################3 
		 ## If list is not in $parms then normal parm check
		 if ( $parms !~/list/i) {  
		 		 ## Check for command parms #'s then validity 
		 		 if ((!($ARGV[0])) || (!($ARGV[1])) || ($parms=~/\-h/x) || ($parms=~/all/x) || ($parms=~/\?/x )) { die Usage(); } 
		 		 ## Check for command parms
		 		 if  ( (!($valid =~/$ARGV[0]/x)) && (!($valid =~/$ARGV[1]/x)) ){ die Usage(); } 
		 		 ## set the command name and app name parm ## 
		 		 if ( $valid =~/$ARGV[0]/x ) { $comn =$ARGV[0]; $appn=$ARGV[1];}  
		 		 else {  $comn=$ARGV[1] ; $appn=$ARGV[0]; } 
		 		 if(($comn=~/build/m) && ( $appn !~/All/)) { die Usage(); } ## make sure they want to rebuild
		 } else { $comn="list"; $appn="All"; } 

		 ########### Security Access Check #######################################
		 if ($0 !~/rccfg/) { 
		 		 ### Read in security file if neccesary 
		 		 rsecfile("$secfile");
        		 if( ($appaccess !~/$appn/) && ($comn !~/status/) )  { 
                		 $report="$date $0 @ARGV  FAILED FOR ACCESS AND LOGGED " ;
                		 record("$report"); 
                		 die &Usage("F"); ## send die access msg
        		 } 
		 }
		 ########### Passed Access Check #######################################
		 ## Passed check log the command send to rccfg in /stats/hostname 
		 record("$report"); 
} 
############################################################
sub rsecfile { 
		 ## Security sub used for secured version only 
		 ##local Var 
		 my $fname="$_[0]"; chomp($fname); 
		 my @temp; 
		 ##local Var 
		 open(fin,$fname) || die " Secured Application Authorization file $fname does not exits \n";  
		 while (<fin>)  { 
		 		 if (!(/^\#/)) { 
		 		 		 @temp=split; 
		 		 		 $appaccess="$appaccess $temp[0] "; 
		 		 } 
		 } 
		 close(fin); 
} 
############################################################
sub Usage {
		 ### generic Usage for secured and unsecured version 
		 ###localVar 
		 		 my $secure; 
		 		 my $access; 
		 		 if ($_[0]) { 
		 		 		 $access="$_[0]"; ## should be "F"  
		 		 } else {  $access="T";} 
		 ###localVar 
		 ##Check if this is a secured version or not 
		  if  ($0 !~ /rccfg/ )  { 
		 		 $secure="T" 
		 } 
		 system("clear"); 
        print <<EOF ;
*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
EOF
		 if (($secure eq "T") && ($access eq "F" )) { 
		 		 print "UNAUTHORIZED APPLICATION ACCESS --\n"; 
		 } 
        print <<EOF ;
        $0  <app name > < command > 
		 $0  <command> <appname> 
		 		 Valid commands: 
		 		 		 start  <appname> = Call link for appname startup 
		 		 		 stop   <appname> = Call link for appname stop 
		 		 		 status <appname> = Call link for appname status 
		 		 		 noauto <appname> = Remove startup link for an application
		 		 		 noauto <appname> = Remove startup link for an application
		 		 		 build  All 		  = Refresh/Recreate all Runlevel links from local dir
		 		 		 		 		    The "All" appname is req and case sensitive 
		 		 		 list 		 		  = Lists all local Runlevel Application Names 

		 		 Valid appnames 
EOF
		 if ($secure eq "T" ) {  
		 		 print "$appaccess "; 
		 } else { 
        print <<EOF ;
		 		       <appname> = Pattern to match <full field will be matched, case sensitive >
		 		             All = Run the command for all, case sensitive 
EOF
		 }  
		 if (($secure) && ($access eq "F" )) { 
		 		 print "\n\n---UNAUTHORIZED APPLICATION ACCESS WAS RECORDED----\n"; 
		 } 
        print <<EOF ;

*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
EOF
exit;
}
###########################################################
sub record {
		 ### record valid commands to log file 
        ### local Vars ###########################3
        my $msg=$_[0];
		 #$rclog is our log file 
        if (!( -d ("$rclog"))) { die "$rclog does not exist ABORT";
exit :}
        open(record,">>$rccfglog");
        print record "$msg \n";
        close(record);
}
############################################################
############################################################33
sub read_cfg  { 
		 # Read in Global variables 
		 #my $gscripts; my $stlink; my $stplink; my $rclog; my $lscripts; my $secaccess; 
		 ##########################Local Vars 
		 my $match="gscripts lscripts stlink stplink rclog secaccess "; ## 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
############################################################
##### file name: rccfg.config
##### purpose:		 To set config for rrcfg script and helper apps
#####		 
##### author: Bill Mclean
#############################################################
#####		 location /etc/rccfg.config   
#####		 File permission 600 - only root needs access 
#############################################################

#############################################################
#####		 Global script location 
#####		 format : 
#####		 gscripts <script full path location>   
#####		 example 		 
#####		 gscripts /appscripts 
#############################################################

gscripts /appscripts/global

#############################################################
#####		 local script location 
#####		 format : 
#####		 lscripts <script full path location>   
#####		 example 		 
#####		 lscripts /appscripts/local 
#############################################################

lscripts /appscripts/local

#############################################################
#####		 start link dir
#############################################################
#####		 start link dir
#####		 format : 
#####		 stlink <full path location>   
#####		 example 		 
#####		 stlink /etc/rc.d/rc2.d 
#############################################################

stlink /etc/rc.d/rc2.d 

#############################################################
#####		 stop link dir
#####		 format : 
#####		 stplink <full path location>   
#####		 example 		 
#####		 stplink /etc/rc.d/rc2.d 
#############################################################

stplink /etc/rc.d/rc0.d 

#############################################################
#####		 rccfg log dir 
#####		 note- /rccfglog.$ldate will be appended to logname
#####		 format : 
#####		 rclog <full path location>   
#####		 example 		 
#####   rclog  /tmp/rclog 
#############################################################

rclog /tmp/rclog  

#############################################################
#####		 Security Access Files Directory Location
#####		 format : 
#####		 secaccess  <Directory name where <command>.access file exists
#####		 example 		 
#####   seaccess /etc
#############################################################

secaccess /etc 
#!/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
########################################################################

