#!/usr/bin/perl # # Lastest Version # --------------- # http://www.Linux-Consulting.com/AutomatedAdmin # chown 750 Update.client.sh # chown 755 Update.pl # # # ------------------------------------------------------------ # Update all System Files as Needed from MasterServer # Client Hosts run Upgrade.client.sh to call Upgrade.pl # ------------------------------------------------------------ # # Files to check-n-upgrade are defined in: # ---------------------------------------- # MasterServer:/opt/Master/update.patches.txt # # # # Update all System Files as Needed from MasterServer # --------------------------------------------------- # - # - move /etc/passwd /etc/passwd.yymmdd # # # 03-Jan-01 amo Date-of-Birth # 08-Jan-02 amo Added ignore compare if *.lock # 11-Jan-02 amo Added locked differences vs required changes # # # # ================================================================================== # # User and System Dependent stuff # # # Location of the Master Files # ---------------------------- my ( $MasterSvr ) = "MasterServer"; my ( $MasterDom ) = `hostname -d`; my ( $MasterMnt ) = "/opt"; my ( $MasterDir ) = "Master"; # my ( $PatchVer ) -= "0.0"; # # Who should be told about Updates # my ( $MailUser ) = "alvin"; # # # finding other hosts my ( $NET ) = "/net"; # my ( $MNT ) = "/mnt/test"; # # # Which files has been updated and needs to be patched on the clients # my ( $MasterFile ) = "update.patches.txt"; # # # Commands # -------- my ( $DIFF ) = "/usr/bin/diff"; # my ( $MAIL ) = "/bin/mail"; my ( $HOSTNAME ) = "/bin/hostname"; # # # # ============================================================================= # # No changes should be needed below this point # # ============================================================================= # my ( $NM ) = "Update.pl"; # my ( $DEBUG ) = 0; # -d x flag to turn on # # # For User feedback # my ( $LOG ) = "/tmp/${NM}.log"; # # # For what files have been updated and patched # my ( $LogDir ) = "/var/log/update.log"; # # my ( $HOST ) = `$HOSTNAME -s `; chomp ( $HOST ); # # # # # Process the Command Line Options # -------------------------------- &process_cmdline; # # # my ( $mnt ) = "mount $MasterSvr:$MasterMnt $MNT"; # my ( $mntstr ) = " df | grep -i $MasterSvr:$MasterMnt | wc -l "; my ( $mntcnt ) = ` $mntstr `; # # # if ( $mntcnt == 1 ) { # # already mounted # printf "..Already mounted .. $MasterSvr:$MasterMnt $MNT..\n"; # } else { # printf "..$mnt..\n"; # ` $mnt `; $mntcnt = ` $mntstr `; # } # if ( $mntcnt != 1 ) { # printf "$NM: ERROR: Could not mount $MasterSvr:$MasterMnt $MNT..\n"; exit 1; # } # error # ` cd $MNT `; # # if ( ! -d "$MNT/$MasterDir" ) { # printf "$NM: ERROR: Missing Dir=$MNT/$MasterDir..\n"; exit 1; # } # if ( ! -f "$MNT/$MasterDir/$MasterFile" ) { # printf "$NM: ERROR: Missing Update File=$MNT/$MasterDir/$MasterFile..\n"; exit 1; # } # # # # Apply the Patches as defined # ---------------------------- # my ( $patches ) = "$MNT/$MasterDir/$MasterFile"; my ( $patch ) = ""; my ( $upd ) = ""; # my ( $lock ) = 0; my ( $diff ) = 0; # # Keep a Log file of the update sequences # --------------------------------------- $status = open ( FWR, "> $LOG" ); # if ( $status == 0 ) { # printf "$NM: ERROR: $status : Could not open $LOG..\n"; exit 1; # } # error # # # $status = open ( FRD, "< $patches" ); # if ( $status == 0 ) { # printf "$NM: ERROR: $status : Could not open $patches..\n"; exit 1; # } # error # # # Process the Patch File # ---------------------- # while ( ) { # chomp ( $patch = $_ ); # # Apply the Patches and skip comments # if ( ! /^#/ ) { # if ( /^Update.Version/ ) { # ( $upd, $PatchVer ) = split ( /\s+/, $patch ); # printf "..$HOST: Applying Patches $PatchVer..\n\n"; printf FWR "..$HOST: Applying Patches $PatchVer..\n\n"; # } else { # # code : file : targetfile: commands # ( $l, $d ) = &ProcessPatches ( split ( /\=/, $patch ) ); $lock += $l; $diff += $d; # } # } # found patch to run # } # read all the patches to apply # # # Send Status Email # ----------------- # &process_msg ( $lock, $diff ); # printf "..lock=$lock...diff=$diff...DONE..\n"; printf FWR "..lock=$lock...diff=$diff...DONE..\n"; # close ( FRD ); close ( FWR ); # # ` cd `; ` umount $MNT ` ; # # exit 0; # # ======================================================= # sub ProcessPatches { my ( $code ) = @_[0]; my ( $patch ) = @_[1]; # Master FileName my ( $lfile ) = @_[2]; # local filename my ( $diff2 ) = @_[3]; # pre-processor commands my ( $cp2 ) = @_[4]; # Post-processor commands # # truncate leading spaces # $patch =~ s/^\s+//; # $diff2 =~ s/^\s+//; # leading space $diff2 =~ s/\s+$//; # truncate trailing space # # my ( $cmd ) = "$DIFF $NET/$MasterSvr/$patch $patch"; my ( $lock ) = 0; my ( $diff ) = 0; my ( $status ) = 0; # printf "..$cmd..\n"; printf FWR "..$cmd..\n"; # # # Pre-Process the command for the differences # ------------------------------------------- # - ignore self during diff comparason # # # Do the comparason # ----------------- # if ( "$diff2" eq "auto.mach" || "$diff2" eq "auto.home" ) { # # for comparing /etc/auto.mach on various hosts # ` cat $NET/$MasterSvr/$patch | egrep -iv "$MasterSvr|$HOST" > /tmp/diff.Master.$diff2 ` ; ` cat $patch | egrep -iv "$MasterSvr|$HOST" > /tmp/diff.Host.$diff2 ` ; # if ( $DEBUG >= 1 ) { # printf "....cat $NET/$MasterSvr/$patch | egrep -iv '$MasterSvr|$HOST' > /tmp/diff.Master.$diff2 ..\n"; printf "....cat $patch | egrep -iv '$MasterSvr|$HOST' > /tmp/diff.Host.$diff2 ..\n" ; # } # $cmd2 = "$DIFF /tmp/diff.Master.$diff2 /tmp/diff.Host.$diff2 "; # @status = ` $cmd2 `; # printf "....$cmd2..\n"; printf FWR "....$cmd2..\n"; # } else { # @status = ` $cmd `; # } # if ( $#status >= 0 ) { # # if ( -f "$patch.update.lock" ) { # $lock = 1; # Files are different and locked # printf "....SKIPPING: Different but locked $patch..\n\n"; printf FWR "....SKIPPING: Different but locked $patch..\n\n"; # } else { # $diff = 1; # Files are different and locked # # Display the differences # printf "....%s..\n", join ( " ", @status ); printf FWR "....%s..\n", join ( " ", @status ); # # # update command # -------------- # if ( "x$cp2" ne "x" ) { # printf "....cp $NET/$MasterSvr/$patch /tmp ; $cp2 ..\n"; # } # post process file # } # different # } # different it # # return ( $lock, $diff ); # } # ProcessPatches # # # sub process_msg { # my ( $lock ) = @_[0]; my ( $diff ) = @_[1]; # my ( $stat ) = "is current"; # $stat = "-- $lock locked files " if ( $lock > 0 ); $stat .= "-- requires $diff Updates" if ( $diff > 0 ); # my ( $msg ) = "$HOST $stat to PatchLevel $PatchVer "; # # printf "..$msg.. \n\n"; printf FWR "..$msg \n\n"; # ` $MAIL -s "$msg " $MailUser < $LOG `; # # } # process_msg # # # Process the command line args # ----------------------------- # sub process_cmdline { my ( $id ) = 0; # my ( $arg ) = ""; # while ( $id <= $#ARGV ) { # $arg = $ARGV[$id]; # # if ( $arg eq "-h" ) { &usage ; exit 0; # } elsif ( $arg eq "-d" ) { # $id += 1; $DEBUG = $ARGV[$id]; $DEBUG = 1 if ( $DEBUG == 0 ) # } elsif ( $arg eq "-s" ) { $id += 1; $MasterSvr = $ARGV[$id]; # Check against this Master Server } # $id += 1; # } # end of args # } # process_commandline # # # end of file