Some korn shell scripts that I have written...

This copies knowledge modules for Patrol from network servers to a central location.

#!/bin/ksh
# variable assignment
DAT1=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt
DAT2=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/chosen_few.data
VAR1=`date +%Y%b%d` # assign date (format ddMOyyyy) as value for $VAR1
#
# create directory for current backups
cd /u01/cust_file_backup_dir
mkdir $VAR1
cd /u01/cust_file_backup_dir/$VAR1
touch /u01/cust_file_backup_dir/$VAR1/kmbup.err
#
# send stderror output to log file
exec 2>/u01/cust_file_backup_dir/$VAR1/kmbup.err
#
# loop to select servers from file
for server_name in $(<$DAT1)
      do
            VAR2=$server_name
            mkdir /u01/cust_file_backup_dir/$VAR1/$VAR2
            cd /u01/cust_file_backup_dir/$VAR1/$VAR2
            # loop to select km to be copied from file
            for file_name in $(<$DAT2)
                  do
                        VAR3=$file_name
                        rcp $VAR2:$VAR3 . # copies for to current directory (the period)
                  done # end of loop to select km to be copied from file
            cd /usr/local/scripts/cust_file_bkp_dir/
done # end of loop to select servers from file
#
# throw out temporary name file
rm /usr/local/scripts/cust_file_bkp_dir/data_file_dir/lg_file_name.temp
#
# end of script

This one tidies up after the last script, archiving the oldest directories

#!/bin/ksh
# script to date qualify, and then tar, zip, and remove
# original unarchived directory.
# November 02, 2001 D.Sprouse for LMUNIX at Cummins
export PATH=$PATH:/usr/local/scripts/cust_file_bkp_dir:/usr/bin
# variable assignment
ADRS1=/u01/cust_file_backup_dir
ADRS2=/u01/cust_file_archive_dir/
ADRS3=/usr/local/scripts/cust_file_bkp_dir/
ADRS4=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/ # line10
DAT1=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/temp_file_name_holder
#
# create list of files
cd $ADRS1/
ls > $DAT1
NO_ELMNTS=`ls | wc -l`
echo $NO_ELMNTS
# check for validity of run, there must be mutliple generations to proceed
if (($NO_ELMNTS<5))
      then
           exit 0
fi
#
# pick a directory to archive
cd $ADRS4
for DIR_NAME in $(<$DAT1)
      if [[$VAR001 -z]]
            then
                  VAR001=$DIR_NAME
      fi
      do
            VAR001=`echo $DIR_NAME`
            if (($PREV_DIR -nt $VAR001))
            then
            unset PREV_DIR
            PREV_DIR=`echo $VAR001`
      fi
done
#
# main file processing
cd $ADRS1
tar -cf $PREV_DIR.tar $PREV_DIR
gzip $PREV_DIR.tar
mv $PREV_DIR.tar.gz $ADRS2
cd $ADRS1/$PREV_DIR
rm *.*
cd ..
rmdir $PREV_DIR
# end of program.

This one sends changes to the critproc file on the network servers, /etc/critproc is a data file for the critproc KM used at Cummins.

#!/bin/ksh
#December 2002 D.Sprouse for LMUNIX at Cummins
#
# variable assignment
DAT1=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt
DAT2=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/SSH_line
DAT3=/etc/SSH_line
#
for server in $(<$DAT1)
      do
            VAR01=$server
            rsh $VAR01 cat $VAR01:$DAT3 >> $VAR01:/etc/critproc
      done
#end of program

This one checks sun servers, and if they don't have a notrouter file in /etc puts one there.

#!/bin/ksh
# script to check SunOS server /etc/notrouter file or put one there.
# notrouter.ksh
# May 03, 2002 D.Sprouse for LMUNIX at Cummins
#
# variable assignment
DAT1=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt
DAT2=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/temp_file_name_holder
#
# clean temp file1
cat > $DAT2< EOF
#
# prune the list
awk '$2~/'SunOS'/{print $1}' $DAT1 >> $DAT2
#
for server in $(<$DAT2)
      do
            VAR01=$server
            rsh $VAR01 touch /etc/notrouter
      done
#
#end of program

This one checks network servers running SunOS for the version of Explorer on the box.

#!/bin/ksh
# script to check SunOS server for version# of
# explorer
# November 02, 2001 D.Sprouse for LMUNIX at Cummins
#
# variable assignment
DAT1=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt
DAT2=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/temp_file_name_holder
DAT3=/usr/local/scripts/cust_file_bkp_dir/data_file_dir/PKFGINFO_list.txt
ADRS1=/var/spool/pkg
ADRS2=/usr/local/software/Solaris/SUNWexplo.tar.Z
#
# clean temp file1
cat > $DAT2< EOF
# clean temp file2
cat > $DAT3< EOF
#
# prune the list
awk '$2~/'SunOS'/{print $1}' $DAT1 >> $DAT2
#
for server in $(<$DAT2)
      do
            VAR01=$server
            VAR02=`rsh $VAR01 pkginfo -l SUNWexplo | grep VERSION:`
            VAR03=`echo $VAR02 | awk -F"[ ,]": '{print $1}'`
            VAR04=`rsh $VAR01 pkginfo -l VRTSvxvm | grep VERSION:`
            VAR05=`echo $VAR04 | awk -F"[ ,]": '{print $1}'`
            echo "Server name: $VAR01" >> $DAT3
            echo "Sun Explorer Version: $VAR03" >> $DAT3
            echo "VRTSvxvm Version: $VAR05" >> $DAT3
            echo "$VAR05" >> $DAT3
            echo " " >> $DAT3
      done

This checks to see if an app (tricon) is running

#!/bin/ksh
#script to test for tricon instance running
#put into /etc on after02 and gobora1
#November 26th 2001, Daniel Sprouse for LM UNIX
ps -efa > temp_tester_file
grep reqgen.com temp_tester_file
if (($? <1))
      then
            rm temp_tester_file
      else
            rm temp_tester_file
            cd /u07/app/tricon/com
            ./START_TRICON_ON_AFTER02
fi
exit 0
Hosted by www.Geocities.ws

1