Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- Unix Scripts Tips

Useful Links

- Bash shell HOWTO
- Bourne Shell Man Page
- C Shell Guide
- Korn Shell Resources

depot_collect.sh

#!/bin/posix/sh #$Revision: 4.5 $ # # Author: KC Hogan CSL, Hewlett-Packard (kchogan@fc.hp.com) # Created: Tues Apr 15 14:46:10 MDT 1997 # Modified: Tue Mar 10 09:02:59 MST 1998 # #set -xv uctime=`date` scriptversion="A.03.00" osrev=`uname -r|awk -F. '{ print $2 }'` osver=`uname -r|awk -F. '{ print $2"."$3 }'` HOST=`hostname|awk -F. '{ print $0}'` export PATH=/usr/bin:/usr/sbin:/sbin unalias `alias | cut -f1 -d"="` HOMEDIR="$HOME" if [ -z "$HOMEDIR" ] then HOMEDIR="/tmp" fi set -o nounset LANG= LC_COLLATE= # default directory in which to create files WORKDIR=/tmp PSIDIR=$WORKDIR # name of standalone depot PSIFILE file PSIFILE=`uname -n` PSIEXT=".dp" PSIFILE_TMP=full.ls # workfile for swlist command WORKFILE=patches.ls WORKFILE1=subproducts.ls # workfile for breakup WORKFILE2=files.ls # workfiles for checking arch and OS's WORKFILE3=os.ls WORKFILE4=separate.ls WORKFILE5=check.ls OSFILE=os_file.ls #set up script name for subsequent use in messages SCRIPT_NAME=$0 #header/trailer tags header_tag=TH trailer_tag=TT #depot tags depot_start=DS depot_end=DE depot_tag=DP # current directory CWD=`pwd` # create list of depot patches ptrack_dep() { cat $WORKDIR/$WORKFILE | \ awk 'BEGIN {start="";lastline=""; fileset=""; yymmdd=""; machine""; os_name=""; os_rel=""; architecture=""; patch_state=""; osfile="/tmp/os_file.ls"} {if ($1) {if ($1 == "vendor") {start="start"} else if (($1 == "product") && (lastline !~ /vendor/)) {start="start"} else if ($1 == "fileset") {patch_product=substr(lastline,1,(index(lastline, ".") - 1)) fileset=substr(lastline, (index(lastline, ".") + 1)) } #need check for date field that is displayed differently using #11.X SD else if ($1 == "date") {if ($2 ~ /[0-9]+/) {yymmdd = substr($2,7,2) yymmdd = yymmdd substr($2,1,2) yymmdd = yymmdd substr($2,4,2) } else {mon=$3 monthno["Jan"] = "01" monthno["Feb"] = "02" monthno["Mar"] = "03" monthno["Apr"] = "04" monthno["May"] = "05" monthno["Jun"] = "06" monthno["Jul"] = "07" monthno["Aug"] = "08" monthno["Sep"] = "09" monthno["Oct"] = "10" monthno["Nov"] = "11" monthno["Dec"] = "12" yymmdd = substr($7,3,2) yymmdd = yymmdd monthno[mon] if (length ($4) == 1) yymmdd = yymmdd "0" $4 else yymmdd = yymmdd $4 } } else if ($1 == "os_name") {os_name="" os_name=$2} else if ($1 == "machine_type") {machine="" machine=$2} else if ($1 == "os_release") {os_rel="" os_rel=$2 print $2 >> osfile} else if ($1 == "architecture") {architecture="" architecture=$2} else if ($1 == "patch_state") {patch_state="" patch_state=$2} else if ($1 == "DS") { printf ("DS "$3"\n") } else if ($0 =="DE") { printf ("DE\n") } else lastline=$1 } else { if ((start) && (fileset)) { if (fileset ~ /PH.._[0-9]*/) { if ( ! (patch_state ~ /superseded/) ) { printf ("PUAD%-10s%s%-16s%-22s%-21s%-40s\n", fileset,yymmdd,os_name,machine, architecture,os_rel) lastline=""; fileset=""; yymmdd=""; patch_product="" } } else if (patch_product ~ /PH.._[0-9]*/) { if ( ! (patch_state ~ /superseded/) ) { printf ("PUAD%-10s%s%-16s%-22s%-21s%-40s\n", patch_product,yymmdd,os_name,machine, architecture,os_rel) lastline=""; fileset=""; yymmdd=""; patch_product="" } } } } }' >> $PSIDIR/$PSIFILE_TMP } # create list of depot products & filesets swinv_dep() { cat $WORKDIR/$WORKFILE1 | \ awk 'BEGIN {start="";savename=""; product=""; subproduct=""; fileset=""; revision=""; yymmdd=""; os_name=""; machine=""; os_rel=""; architecture=""; patch_state=""; osfile="/tmp/os_file.ls"} {if ($1) {if ($1 ~ /\./) savename=$1 else if ($1 == "vendor") {start="start"} else if (($1 == "product") && (lastline !~ /vendor/)) {start="start"} else if ($1 == "fileset") {nofields=split(savename,fields,"."); product=fields[1]; fileset=fields[nofields]; if (nofields < 3) subproduct=""; else subproduct=fields[2]; } else if ($1 == "revision") {revision="" revision=$2} else if ($1 == "os_name") {os_name="" os_name=$2} else if ($1 == "machine_type") {machine="" machine=$2} else if ($1 == "os_release") {os_rel="" os_rel=$2 print $2 >> osfile} else if ($1 == "architecture") {architecture="" architecture=$2} else if ($1 == "patch_state") {patch_state="" patch_state=$2} else if ($1 == "DS") { printf ("DS "$3"\n") } else if ($1 =="DE") { printf ("DE\n") } #need check for date field that is displayed differently using #11.X SD else if ($1 == "date") {if ($2 ~ /[0-9]+/) {yymmdd = substr($2,7,2) yymmdd = yymmdd substr($2,1,2) yymmdd = yymmdd substr($2,4,2) } else {mon=$3 monthno["Jan"] = "01" monthno["Feb"] = "02" monthno["Mar"] = "03" monthno["Apr"] = "04" monthno["May"] = "05" monthno["Jun"] = "06" monthno["Jul"] = "07" monthno["Aug"] = "08" monthno["Sep"] = "09" monthno["Oct"] = "10" monthno["Nov"] = "11" monthno["Dec"] = "12" yymmdd = substr($7,3,2) yymmdd = yymmdd monthno[mon] if (length ($4) == 1) yymmdd = yymmdd "0" $4 else yymmdd = yymmdd $4 } } } else {if ((start) && (fileset) && (fileset !~ /PH.._[0-9]*/)) { if ( ! (patch_state ~ /superseded/) ) {printf ("SUADNF%-16s%-16s%-16s%-32s%s%-16s%-22s%-21s%-30s\n", product, subproduct, fileset, revision, yymmdd, os_name, machine, architecture, os_rel) savename=""; product=""; subproduct=""; fileset="" revision=""; yymmdd="" } } } }' >> $PSIDIR/$PSIFILE_TMP } get_system() { earch=`uname -m|awk -F/ '{ print $2 }'` case $earch in 7*) comarch="700";; 8*) comarch="800";; *) break;; esac echo "" echo "Please enter architecture, 700 or 800 ? \c" read inarch case $inarch in 700|800 ) compare_arch; break;; *) echo "You must enter either 700 or 800 architecture"; echo "Please try again"; echo "" get_system; break;; esac } compare_arch() { if [ "$inarch" = "$comarch" ] then get_os else echo "" echo "You are running on a $earch system, but you have selected"; echo "$inarch architecture for your depot."; echo "" echo "Are you sure you want $inarch architecture, [Y] or N ? \c"; read newreply if [ -z "$newreply" ] # default to Yes then newreply="Y" fi case $newreply in [yY]|[yY][eE][sS]) newreply=Y; break;; esac if [ "$newreply" = "Y" ] then get_os else get_system fi fi } valid_os() { if [ "$inarch" = "700" ] then if [ "$firstos" ] then case $firstos in 10.00|10.01|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$firstos is not a valid OS for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$secondos" ] then case $secondos in 10.00|10.01|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$secondos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$thirdos" ] then case $thirdos in 10.00|10.01|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$thirdos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$fourthos" ] then case $fourthos in 10.00|10.01|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$fourthos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi else if [ "$firstos" ] then case $firstos in 10.00|10.01|10.08|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$firstos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$secondos" ] then case $secondos in 10.00|10.01|10.08|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$secondos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$thirdos" ] then case $thirdos in 10.00|10.01|10.08|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$thirdos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi if [ "$fourthos" ] then case $fourthos in 10.00|10.01|10.08|10.09|10.10|10.16|10.20|10.24|10.30|11.00 ) break;; * ) echo "" echo "$fourthos is not a valid os for your chosen architecture"; echo "Please try again"; echo "" get_os; break;; esac fi fi } get_os() { echo "" echo "Please enter at least 1, but not more than 4 OS's" echo "Each OS must be separated by a colon" echo "Example: 10.00:10.20:10.30" echo "" echo "Please enter OS(s) now: \c" read inos firstos=`print $inos | awk -F: '{ print $1 }'` secondos=`print $inos | awk -F: '{ print $2 }'` thirdos=`print $inos | awk -F: '{ print $3 }'` fourthos=`print $inos | awk -F: '{ print $4 }'` fifthos=`print $inos | awk -F: '{ print $5 }'` if [ -z "$firstos" ] then get_os fi if [ "$fifthos" ] then echo "You have entered too many OS's." echo "Only the following 4 will be processed:" echo "$firstos $secondos $thirdos $fourthos" echo "" inos="$firstos:$secondos:$thirdos:$fourthos" fi case $inarch in 700|800 ) valid_os; break;; * ) break;; esac } check_os() { cat $WORKDIR/$WORKFILE4 |\ awk 'BEGIN {FS = "."; WORKFILE5="/tmp/check.ls"; cnt="0"} {if ($0) for ( i = 1; i <= NF; i++ ) {first = $2 second = $3 if ( (first ~ /^1\?/) && (second ~ /\*/) ) {first = "11" second = "00"} total = sprintf("%s.%s", first, second) if (total == firstos) next else if (total == secondos) next else if (total == thirdos) next else if (total == fourthos) next else if (total ~ /\*/) next else if ( (total ~ /\[/) || (total ~ /\]/) ) next else {name = first "." second if (name in missing) next else missing[name] = first "." second } } } END { for (ind in missing) {print missing[ind] >> WORKFILE5} }' firstos=$firstos secondos=$secondos thirdos=$thirdos fourthos=$fourthos } missing_os() { echo "" echo "You have the following OS(s) in your depot that you did" echo "not include in your selected OS list:\n" cat $WORKDIR/$WORKFILE5 | \ awk 'BEGIN {} {if ($1) print $0 }' echo "" echo "You may want to re-run the depot collection script and" echo "include these OS's, or run the depot collection script" echo "a second time after you have renamed the current" echo "configuration file to ensure that these OS's get" echo "included in a separate configuration file" echo "" } separate_os() { cat $WORKDIR/$OSFILE | \ awk 'BEGIN { FS = "|"; WORKFILE4="/tmp/separate.ls" } {if ($1) {for ( i = 1; i <= NF; i++ ) print $i >> WORKFILE4 } }' } # if the file is too large, break it into parts breakup() { echo "Breaking up depot file" cat $PSIDIR/$PSIFILE_TMP | \ awk 'BEGIN{} {if ($1) ++numlines } END { tmp_numfiles = numlines / 500 tmp_num = split(tmp_numfiles, numarr, ".") numfiles = (numarr[tmp_num] > 0) ? (numarr[1] + 1) : (numarr[1]) printf (numfiles) }' >> $PSIDIR/$WORKFILE2 numfiles=`cat $PSIDIR/$WORKFILE2` #make the header/trailer info _os_version=`uname -r` _hw_model=`uname -m` _sys_name=`uname -n` today=`date +%y%m%d` cat $PSIDIR/$PSIFILE_TMP | \ awk 'BEGIN{count=1; fileext=1; trailer_tag="TT"; header_tag="TH"; serial="NO-SERIAL-"; model="no-model"; handle="-----NO--HANDLE-----"; group="------NO--GROUP-ID------"; office="-no-"; os="UX"} {if (numfiles != 0) {if (($1 ~ /PUAD*/) && (count <= 500)) {count++ filename = sprintf("%s/%s%s%s", PSIDIR, PSIFILE, fileext, PSIEXT) print $0 >> filename } else if (($1 ~ /SUAD*/) && (count <= 500)) {count++ filename = sprintf("%s/%s%s%s", PSIDIR, PSIFILE, fileext, PSIEXT) print $0 >> filename } else if (count <= 500) {count++ filename = sprintf("%s/%s%s%s", PSIDIR, PSIFILE, fileext, PSIEXT) print $0 >> filename } else {old_filename = sprintf("%s/%s%s%s", PSIDIR, PSIFILE, fileext, PSIEXT) #put a trailer_tag on the old file print trailer_tag serial model handle group office sh_version os today os_version hw_model sys_name >> old_filename numfiles-- fileext++ count=0 filename = sprintf("%s/%s%s%s", PSIDIR, PSIFILE, fileext, PSIEXT) {if ($1 ~ /TH*/) {print $0 >> filename} else if ($1 ~/DP*/) {print $0 >> filename} else if ($1 ~ /TT*/) {} #do not print a trailer else {print header_tag serial model handle group office sh_version os today os_version hw_model sys_name >> filename {if ($1 ~ /PUAD*/) {printf ("PURE\n") >> filename printf ("PUNF\n") >> filename print $0 >> filename } else if ($1 ~ /SUAD*/) {printf ("SURE\n") >> filename print $0 >> filename } else {print $0 >> filename} } } } } } }' numfiles=$numfiles PSIDIR=$PSIDIR PSIFILE=$PSIFILE PSIEXT=$PSIEXT sh_version=$scriptversion today=$today os_version=$_os_version hw_model=$_hw_model sys_name=$_sys_name } depot_path() { rm -f $WORKDIR/$WORKFILE rm -f $WORKDIR/$WORKFILE1 rm -f $WORKDIR/$WORKFILE2 numfiles=0 echo "" echo "Enter path to depot, or path to file containing a list of depots" echo "(one depot per line in the file).\n" read depot_file if [ -d $depot_file ] then if [ -r $depot_file ] then depot_path="$HOST:$depot_file" echo "$depot_start\tDepot: $depot_path" >> $WORKDIR/$WORKFILE echo "$depot_start\tDepot: $depot_path" >> $WORKDIR/$WORKFILE1 echo "" echo "Analyzing $depot_path" swlist -v -s $depot_path -l fileset -a date -a os_name -a machine_type -a os_release -a architecture -a patch_state >> $WORKDIR/$WORKFILE swlist -v -s $depot_path -l subproduct -l fileset -a revision -a date -a os_name -a machine_type -a os_release -a architecture -a patch_state >> $WORKDIR/$WORKFILE1 echo "$depot_end\n" >> $WORKDIR/$WORKFILE echo "$depot_end\n" >> $WORKDIR/$WORKFILE1 else echo "No read permission on directory: $depot_file" exit 1 fi elif [ -f $depot_file ] then if [ -r $depot_file ] then { exec < $depot_file while read -r depot do depot_path="$HOST:$depot" echo "$depot_start\tDepot: $depot_path" >> $WORKDIR/$WORKFILE echo "$depot_start\tDepot: $depot_path" >> $WORKDIR/$WORKFILE1 echo "" echo "Analyzing $depot_path depot" swlist -v -s $depot_path -l fileset -a date -a os_name -a machine_type -a os_release -a architecture -a patch_state >> $WORKDIR/$WORKFILE swlist -v -s $depot_path -l subproduct -l fileset -a revision -a date -a os_name -a machine_type -a os_release -a architecture -a patch_state >> $WORKDIR/$WORKFILE1 echo "$depot_end\n" >> $WORKDIR/$WORKFILE echo "$depot_end\n" >> $WORKDIR/$WORKFILE1 done } else echo "No read permission on file: $depot_file" exit 1 fi else echo "" echo "Depot file does not exist." echo "Check the path to ensure it was typed in correctly." echo "\n" depot_path fi } confirm() { echo "" echo "Copyright (c) Hewlett-Packard 1997-1998. All Rights Reserved." echo "" echo " depot_collect.sh version: $scriptversion" echo "" echo "This script will collect information about filesets and installed" echo "patches from your depot into the file $PSIDIR/$PSIFILE$PSIEXT for" echo "subsequent transfer to Hewlett-Packard." echo "" echo "When running this script, you will be prompted for a depot to" echo "analyze, and the architecture and OS(s) of that depot." echo "" echo "You must specify at least one architecture and up to four OS's" echo "" echo "You may specify a depot path for a single depot when prompted," echo "or you may create a file which contains several depots, and " echo "enter the path to that file when prompted. If you choose to " echo "create a file, this file must be created before you can continue, " echo "and each depot path in that file must be followed by a carriage " echo "return." echo "" echo "Depots containing more than 500 patches/products may be broken" echo "into separate files using the -b argument for better performance." echo "" echo "This script is for 10.X or 11.X system depots ONLY." echo "" echo "Do you wish to continue, [Y] or N ?\c" read reply if [ -z "$reply" ] # default to Yes then reply="Y" fi case $reply in [yY]|[yY][eE][sS]) reply=Y; break;; esac if [ "$reply" != "Y" ] then echo "Exiting" exit 0 fi } write_header() { _serial='NO-SERIAL-' _model='no-model' _handle='-----NO--HANDLE-----' _group='------NO--GROUP-ID------' _office='-no-' typeset -L8 _sh_version=$scriptversion typeset -L8 _os_version=`uname -r` typeset -L8 _hw_model=`uname -m` typeset -L20 _sys_name=`uname -n` print -n - "$1" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_serial" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_model" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_handle" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_group" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_office" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_sh_version" >> $PSIDIR/$PSIFILE_TMP ; print -n - "UX" >> $PSIDIR/$PSIFILE_TMP ; print -n - `date +%y%m%d` >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_os_version" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$_hw_model" >> $PSIDIR/$PSIFILE_TMP ; print - "$_sys_name" >> $PSIDIR/$PSIFILE_TMP ; # write_depot } print_usage() { echo "usage for: $SCRIPT_NAME [-d <dir>]"; echo "" echo " -d: creation path. Tells the script to create the"; echo " Patch System File (psifile) in the specified"; echo " directory (default directory is /tmp)"; echo "" echo " -b: breakup depot files. Tells the script to break"; echo " the Patch System File (psifile) into several"; echo " smaller files for performance. The file will"; echo " be broken into chunks of 500 patches/filesets"; echo " per file."; echo "" echo " -h: print this helpful message again"; } write_depot() { print -n - "$depot_tag" >> $PSIDIR/$PSIFILE_TMP ; print -n - "$inarch" >> $PSIDIR/$PSIFILE_TMP ; print - "$inos" >> $PSIDIR/$PSIFILE_TMP ; } flag=0 while [ $# -gt 0 ] do case $1 in -d) shift; if [ $# -eq 0 ] then echo "Missing directory." print_usage exit 1 fi if [ $1 = "^-.*" ] then echo "Missing directory." print_usage exit 1 fi if [ -d $1 ] then if [ -w $1 ] then PSIDIR=$1 shift else echo "No write permission on directory: $1" exit 1 fi else echo "Specified directory is not." exit 1 fi;; -h) print_usage; exit 1;; -b) shift; flag=1;; *) print_usage; exit 1;; esac done confirm # remove the current file(s) echo "" echo "removing " $PSIDIR/$PSIFILE*$PSIEXT rm -f $PSIDIR/$PSIFILE*$PSIEXT if [ $osrev -lt 10 ] then # Give error message and exit echo "" echo "You have attempted to run $SCRIPT_NAME on an HP-UX $osver system" echo "" echo "This script is for 10.X or 11.X system depots ONLY." echo "To collect information on systems other than 10.X or 11.X depots," echo "execute the cpm_collect.sh script." echo "Exiting ... " exit 0 else # get arch and OS's get_system # get depot path information depot_path # create list of patches echo "" echo "Creating list of depot patches in $PSIDIR/$PSIFILE$PSIEXT..." write_header "$header_tag" write_depot echo "PURE " >> $PSIDIR/$PSIFILE_TMP echo "PUNF " >> $PSIDIR/$PSIFILE_TMP ptrack_dep write_header "$trailer_tag" # create list of products and filesets echo "" echo "Creating list of depot products and filesets in $PSIDIR/$PSIFILE$PSIEXT..." write_header "$header_tag" echo "SURE " >> $PSIDIR/$PSIFILE_TMP swinv_dep write_header "$trailer_tag" #check the OS's against specified OS's separate_os check_os #notify user of OS's that are in their depot, but not specified if [ -r $WORKDIR/$WORKFILE5 ] then missing_os fi #break up files if requested if [ $flag -eq 1 ] then breakup else cp $PSIDIR/$PSIFILE_TMP $PSIDIR/$PSIFILE$PSIEXT echo "The file $PSIDIR/$PSIFILE$PSIEXT has been created." fi # remove the working files rm -f $WORKDIR/$WORKFILE rm -f $WORKDIR/$WORKFILE1 rm -f $WORKDIR/$WORKFILE2 rm -f $WORKDIR/$WORKFILE3 rm -f $WORKDIR/$WORKFILE4 rm -f $WORKDIR/$WORKFILE5 rm -f $PSIDIR/$PSIFILE_TMP rm -f $WORKDIR/$OSFILE fi # inform of results i=1 while [ $i -le $numfiles ] do filepath="$PSIDIR/$PSIFILE$i$PSIEXT" if [ -f "$filepath" ] then echo "The file $filepath has been created." echo "You are now ready to transfer $filepath to Hewlett-Packard." fi i=`expr $i + 1` done #### END OF SCRIPT

Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries