Archive

Archive for the ‘Shell Scripts’ Category

Find the Bigest Number

if [ $# -ne 3 ]
    then
 echo “$0: number1 number2 number3 are not given” >&2
        exit 1   
    fi
    n1=$1
    n2=$2
    n3=$3
    if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
    then
 echo “$n1 is Bigest number”
    elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]        
    then
 echo “$n2 is Bigest number”
    elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]        
    then
        echo “$n3 is Bigest number”
    elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
    then
 echo “All the three numbers are equal”   
    else
        echo “I can not figure out which number is biger”   
    fi

Categories: Shell Scripts

BaseLine Scripts

#!/bin/sh

#————————————————————————#

# This script will backup the intec database and application files #

# #

# Environment for the oracle database on intec test#

#——————————————————————————————–#

ORACLE_BASE=/opt/app/oracle; export ORACLE_BASE #

ORACLE_HOME=$ORACLE_BASE/product/9.2.0.6; export ORACLE_HOME #

ORACLE_OWNER=oracle; export ORACLE_OWNER #

ORACLE_TERM=vt220; export ORACLE_TERM #

PATH=$PATH:$ORACLE_HOME/bin:/usr/bin:/opt/bin:/usr/ccs/bin; export PATH #

LD_LIBRARY_PATH=$ORACLE_HOME/lib: export LD_LIBRARY_PATH #

#——————————————————————————————–#

#————————————————#

# Append this to the end of the baseline number #

#————————————————#

BASELINE_NUM=$1 # the front name for the current baseline being taken #

BASELINE_DIR=$2 # directory that the files will be stored into #

BASELINE_DATE=`date | sed -e “s/:/_/g” | sed -e “s/ /_/g”`

APP_INTERNAL_DIR=’bin cfg lib utils’

#—————————-#

# TEST for the entry name #

#—————————-#

if [ "$BASELINE_NUM" = "" ];then

echo “missing the baseline name …..”

echo “usage:<$0 <baseline_(number)> <backup dir> example:baseline_intec.sh baseline_4 /backup”

exit 1

fi

#————————————–#

# TEST for the backup directory entry #

#————————————–#

if [ "$BASELINE_DIR" = "" ];then

echo “missing the backup directory name …..”

echo “usage:<$0 <baseline_(number)> <backup dir> example:baseline_intec.sh baseline_4 /backup”

exit 1

fi

BASELINE_FNAME=”INTEC_${BASELINE_NUM}_${BASELINE_DATE}”

COMPLETE_BASE_PATH=$BASELINE_DIR/$BASELINE_FNAME

if [ ! -d $COMPLETE_BASE_PATH ];then

mkdir $COMPLETE_BASE_PATH

fi

#————————————————-#

# Decide on the TNS #

#————————————————-#

HOSTNAME=`hostname`

HOST_TYPE=`echo “$HOSTNAME” | grep “nitp”`

if [ "$HOST_TYPE" = "" ];then

#– Means its the test server –#

echo “#————————————#”

echo “# DOING BASELINE ON THE TEST SERVER #”

echo “#————————————#”

 

ORACLE_SID=OITTEST1; export ORACLE_SID

APP_DIR=/product/ict/TST

TNS_TYPE=”OITTEST1″

else

# Means its the production server #

echo “#—————————————–#”

echo “# DOING BASELINE ON THE PRODUCTION SERVER #”

echo “#—————————————–#”

ORACLE_SID=OITPROD1; export ORACLE_SID

APP_DIR=/product/ict/PRD

TNS_TYPE=”OITPROD1″

fi

echo “#———————————————–#”

echo “# WELCOME TO THE EVENTLINK BASELINE SCRIPT #”

echo “#———————————————–#”

echo “# The script will be baselineing the following #”

echo “# *- Database files #”

echo “# *- Log files #”

echo “# *- Control files #”

echo “# *- Application Files #”

echo “#———————————————–#”

 

#—————————————————-#

# These are the directories that we need to baseline #

#—————————————————-#

echo “## … creating a baseline apps file with name $BASELINE_FNAME_APPS.tar”

cd $APP_DIR

tar -cvf ${COMPLETE_BASE_PATH}/${BASELINE_FNAME}_APPS.tar $APP_INTERNAL_DIR

#———————————————————-#

# These are the database files that we need to baseline #

#———————————————————-#

DATA_DBF=`echo “select file_name from dba_data_files;” | sqlplus baseline/baseline@$TNS_TYPE | grep -i dbf `

DATA_LOG=`echo “select member from v\\$logfile;” | sqlplus baseline/baseline@$TNS_TYPE | grep -i rdo `

DATA_CTR=`echo “select name from v\\$controlfile;” | sqlplus baseline/baseline@$TNS_TYPE | grep -i ctl `

#————————————————#

# Shutting down the database server #

#————————————————#

#

LOOP=1

while [ 1 ]

do

echo “#————————————————-#”

echo “# Would you like to shutdown the databasae server #”

echo “#————————————————-#”

echo “# -* ENTER Y for yes #”

echo “# -* ENTER N for no #”

echo “#————————————————-#”

echo “>>>>: “

read OPT

if [ "$OPT" = "Y" ];then

echo “We are shuting down the database server…”

sleep 10

#————————————

# Dont do this just yet

# $ORACLE_HOME/bin/dbshut

# $ORACLE_HOME/bin/lsnrctl stop

#————————————

break

fi

if [ "$OPT" = "N" ];then

echo “Database server not being shutdown … exiting script …”

exit 0

else

echo “INVALID OPTION PLEASE CHOOSE AGAIN”

fi

done

#—————————————————————#

# Loop through all the of the database files that have been #

# found from the sql commands and add them into the tar file #

#—————————————————————#

FLAG=0

for ORACLE_FILES in `echo “$DATA_DBF $DATA_LOG $DATA_CTR”`

do

if [ $FLAG -eq 0 ];then

echo “————————————————————————–”

echo ” creating file INTEC_ORACLE_BACKUP_`hostname`.tar adding + $ORACLE_FILES “

echo “————————————0————————————-”

tar -cvf ${COMPLETE_BASE_PATH}/INTEC_ORACLE_BACKUP_`hostname`.tar $ORACLE_FILES

FLAG=1

else

echo “————————————————————————-”

echo ” creating file INTEC_ORACLE_BACKUP_`hostname`.tar append + $ORACLE_FILES “

echo “————————————————————————-”

tar -rvf ${COMPLETE_BASE_PATH}/INTEC_ORACLE_BACKUP_`hostname`.tar $ORACLE_FILES

fi

done

echo “—————————————————-”

echo ” BASELINE for INTEC HOST `hostname` ended at `date` “

echo “—————————————————-”

#—————–#

# End script #

#—————–#

exit 0

Categories: Shell Scripts

System Info

#!/bin/ksh

#======================================================================

#

# Filename : system_info_v7.sh

#

#

# Description : Script used to document server configuration

#

#@(#)Version : 2.4 ( 14-Oct-2005 )

#

# Notes : Will take one parameter for 3rd party software

# searches.

# n = no search

# o = oracle only search

# j = java only search

# anything else = full search

# no parameter = full search

#

#———————————————————————-

#

#———————————————————————-

# Functions

#———————————————————————-

f_initialise()

{

DATE=`date +%Y-%m-%d`

thisuser=$(id | cut -f1 -d ” ” | cut -f2 -d “(” | cut -f1 -d “)”)

thisgroup=$(id | cut -f2 -d ” ” | cut -f2 -d “(” | cut -f1 -d “)”)

info_filename=./system_info_v7.txt

temp_filename_1=./temporary_file_1.txt

temp_filename_2=./temporary_file_2.txt

temp_filename_3=./temporary_file_3.txt

temp_filename_4=./temporary_file_4.txt

touch ${info_filename}

touch ${temp_filename_1}

touch ${temp_filename_2}

touch ${temp_filename_3}

touch ${temp_filename_4}

if [[ ! -f ${info_filename} ]]

then

print “Cannot write to ${info_filename} – aborting”

exit 1

fi

if [[ ! -f ${temp_filename_1} ]]

then

print “Cannot write to ${temp_filename_1} – aborting”

exit 1

fi

if [[ ! -f ${temp_filename_2} ]]

then

print “Cannot write to ${temp_filename_2} – aborting”

exit 1

fi

if [[ ! -f ${temp_filename_3} ]]

then

print “Cannot write to ${temp_filename_3} – aborting”

exit 1

fi

if [[ ! -f ${temp_filename_4} ]]

then

print “Cannot write to ${temp_filename_4} – aborting”

exit 1

fi

server_name=$(hostname)

print “\nInformation from ${server_name} on ${DATE}\n” > ${info_filename}

print “\nReport run by ${thisuser}:${thisgroup} (${SHELL})\n” >> ${info_filename}

}

f_hardware()

{

print “\nHARDWARE Information” >> ${info_filename}

print “======== ===========” >> ${info_filename}

case ${op_sys} in

HP-UX)

print “Running model”

hw_info=$(model)

hw_info=$(echo “HP ${hw_info}”)

mc_type=$(model | cut -d ‘/’ -f3)

case ${mc_type} in

A400-44)

mc_name=rp2400

;;

A400-6X)

mc_name=rp2430

;;

A500-44)

mc_name=rp2450

;;

A500-5X)

mc_name=rp2470

;;

A500-6X)

mc_name=rp2470

;;

A500-7X)

mc_name=rp2450

;;

L1000-36)

mc_name=rp5400

;;

L1000-44)

mc_name=rp5400

;;

L1000-5X)

mc_name=rp5400

;;

L1500-5X)

mc_name=rp5430

;;

L1500-6X)

mc_name=rp5430

;;

L1500-7X)

mc_name=rp5430

;;

L1500-8X)

mc_name=rp5430

;;

L2000-36)

mc_name=rp5450

;;

L2000-44)

mc_name=rp5450

;;

L2000-5X)

mc_name=rp5450

;;

L3000-5X)

mc_name=rp5470

;;

L3000-6X)

mc_name=”rp5405/5470″

;;

L3000-7X)

mc_name=rp5470

;;

L3000-8X)

mc_name=rp5470

;;

N4000-65)

mc_name=rp7400

;;

N4000-75)

mc_name=rp7400

;;

rp7410)

mc_name=”rp7405/rp7410″

;;

S16K-A)

mc_name=rp8400

;;

*)

mc_name=”"

;;

esac

print “\n\tModel:\\t\t\t${hw_info} ${mc_name}” >> ${info_filename}

unset mc_name

if [[ -x /usr/sbin/ioscan ]]

then

print “Running ioscan on processor”

typeset i_count=$(/usr/sbin/ioscan -fnkC processor |wc -l)

let i_count=i_count-2

print “\n\tNumber of processors:\t${i_count}” >> ${info_filename}

unset i_count

else

print “/usr/sbin/ioscan not found”

fi

if [[ -x /usr/sbin/cstm ]]

then

print “Running cstm on CPU – please wait”

hw_info=$(echo “selclass qualifier cpu;infolog” | /usr/sbin/cstm | grep “CPU Module” | uniq)

hw_info=$(echo $hw_info | sed -e ’s/Module/Revision/’)

if [[ "${hw_info}" = "" ]]

then

os_ver=$(uname -r | cut -d ‘.’ -f3)

grep CPU /var/tombstones/ts99 | grep PA | uniq > ${temp_filename_4}

case ${os_ver} in

00)

cat ${temp_filename_4} | while read line

do

cpu_type=$(echo ${line} | cut -d ‘ ‘ -f2,3)

done

;;

11)

cat ${temp_filename_4} | while read line

do

cpu_type=$(echo ${line} | cut -d ‘ ‘ -f2)

done

;;

esac

hw_info=${cpu_type}

unset cpu_type

fi

print “\n\tType of processor:\t${hw_info}” >> ${info_filename}

print “Running cstm on memory – please wait”

hw_info=$(echo ’selall;info;wait;infolog;view;done’ | /usr/sbin/cstm |grep ‘Total Configured Memory’ | cut -d ‘:’ -f2)

print “\n\tMemory:\t\t\t${hw_info}” >> ${info_filename}

else

print “/usr/sbin/cstm not found”

fi

if [[ -x /usr/sbin/swapinfo ]]

then

swapsize=$(/usr/sbin/swapinfo -tam | grep total | grep -v /)

swapmb=$(echo $swapsize | cut -d ‘ ‘ -f2)

swapmbtxt=$(echo “${swapmb} MB”)

unset swapsize swapmb

else

print “/usr/sbin/swapinfo cannot be executed by this user”

swapmbtxt=”cannot obtain swap information”

fi

if [[ -x /usr/sbin/kmtune ]]

then

maxsctxt=$(/usr/sbin/kmtune -q maxswapchunks | grep maxswapchunks)

typeset -i maxscnum=$(echo ${maxsctxt} | cut -d ‘ ‘ -f2)

sctxt=$(/usr/sbin/kmtune -q swchunk | grep swchunk)

typeset -i scnum=$(echo ${sctxt} | cut -d ‘ ‘ -f2)

typeset -i maxswapmb=${maxscnum}*${scnum}/1024

maxswaptxt=$(echo “maximum swap space is configured to ${maxswapmb} MB”)

unset sctxt maxsctxt

unset maxswapmb maxscnum scnum

else

print “/usr/sbin/kmtune cannot be executed by this user”

maxswaptxt=”cannot obtain kernel information”

fi

print “\n\tSwap space:\t\t${swapmbtxt}” >> ${info_filename}

print “\t\t\t\t${maxswaptxt}” >> ${info_filename}

unset swapmbtxt maxswaptxt

;;

SunOS)

 

print “Running uname”

servertype=$(uname -m)

if [[ -x /usr/platform/${servertype}/sbin/prtdiag ]]

then

systeminfo=$(echo “`/usr/platform/${servertype}/sbin/prtdiag |grep ‘System Configuration’ |cut -d’:’ -f2`”)

modelinfo=$(echo ${systeminfo} | cut -d ‘ ‘ -f4,5,6)

print “\n\tModel:\\t\t\t\t${modelinfo}” >> ${info_filename}

else

print “/usr/platform/${servertype}/sbin/prtdiag cannot be executed by this user”

fi

if [[ -x /usr/sbin/psrinfo ]]

then

print “Running psrinfo”

typeset i_count=$(/usr/sbin/psrinfo |wc -l)

print “\n\tNumber of processors:\t ${i_count}” >> ${info_filename}

unset i_count

else

print “/usr/sbin/psrinfo cannot be executed by this user”

fi

if [[ -x /usr/platform/${servertype}/sbin/prtdiag ]]

then

print “Running prtdiag”

systeminfo=$(echo “`/usr/platform/${servertype}/sbin/prtdiag |grep ‘System Configuration’ |cut -d’:’ -f2`”)

cpuinfo=$(echo ${systeminfo} | cut -d ‘ ‘ -f9,10)

cpustrsize=${#cpuinfo}

(( cpustrsize=${cpustrsize}-1 ))

dispcpuinfo=$(print ${cpuinfo} | cut -c 1-${cpustrsize})

print “\n\tCPU:\\t\t\t\t${dispcpuinfo}” >> ${info_filename}

unset cpuinfo cpustrsize dispcpuinfo

else

print “/usr/platform/${servertype}/sbin/prtdiag cannot be executed by this user”

fi

if [[ -x /usr/sbin/prtconf ]]

then

print “Running prtconf”

memsize=$(/usr/sbin/prtconf | grep ‘Memory size’ | cut -d ‘ ‘ -f3)

print “\n\tMemory:\\t\t\t\t${memsize} MB” >> ${info_filename}

unset memsize

else

print “/usr/sbin/prtconf cannot be executed by this user”

fi

if [[ -x /usr/sbin/swap ]]

then

print “Running swap”

memsize=$(/usr/sbin/swap -s | grep ‘total’ | cut -d ‘ ‘ -f2)

memstrsize=${#memsize}

(( memstrsize=${memstrsize}-1 ))

typeset -i memmb=$(echo ${memsize} | cut -c 1-${memstrsize})

(( memmb=${memmb}/1024 ))

print “\n\tSwap space:\\t\t\t${memmb} MB” >> ${info_filename}

unset memsize memstrsize memmb

else

print “/usr/sbin/swap cannot be executed by this user”

fi

;;

esac

}

f_operating_system()

{

print “\n\nOPERATING SYSTEM Information” >> ${info_filename}

print “========= ====== ===========” >> ${info_filename}

case ${op_sys} in

HP-UX)

print “Running uname”

opsys_info=$(uname -s)

print “\n\tOperating System:\t${opsys_info}” >> ${info_filename}

opsys_info=$(uname -r)

print “\n\tRelease:\t\t${opsys_info}” >> ${info_filename}

opsys_info=$(uname -v)

print “\n\tVersion:\t\t${opsys_info}” >> ${info_filename}

opsys_info=$(getconf KERNEL_BITS)

print “\n\tWord size:\t\t${opsys_info} bits” >> ${info_filename}

unset opsys_info

if [[ -x /usr/sbin/swlist ]]

then

print “Running swlist to check patch bundle – please wait”

sw_info=$(/usr/sbin/swlist | grep -e QPK -e GOLD)

sw_date=$(echo ${sw_info} | cut -d ‘,’ -f2)

sw_info=$(echo ${sw_info} | cut -d ‘ ‘ -f1)

print “\n\tLatest patch bundle:\t${sw_date} ${sw_info}\n” >> ${info_filename}

unset sw_info sw_date

else

print “/usr/sbin/swlist not found”

fi

if [[ -x /usr/contrib/bin/show_patches ]]

then

print “Running show_patches – please wait”

print “\nOutput from show_patches:\n” >> ${info_filename}

/usr/contrib/bin/show_patches >> ${info_filename}

else

print “/usr/contrib/bin/show_patches not found”

fi

;;

SunOS)

print “Running uname”

opsys_info=$(uname -s)

print “\n\tOperating System:\t\t${opsys_info}” >> ${info_filename}

opsys_info=$(uname -r)

print “\n\tRelease:\t\t\t${opsys_info}” >> ${info_filename}

opsys_info=$(uname -v)

print “\n\tVersion:\t\t\t${opsys_info}” >> ${info_filename}

unset opsys_info

if [[ -x /usr/bin/isainfo ]]

then

word_size=$(/usr/bin/isainfo -kv | cut -c 1-2)

print “\n\tWord size:\t\t\t${word_size} bits” >> ${info_filename}

unset word_size

else

print “/usr/bin/isainfo cannot be executed by this user”

fi

;;

esac

}

f_kernel()

{

print “\n\nKERNEL Information” >> ${info_filename}

print “====== ===========” >> ${info_filename}

case ${op_sys} in

HP-UX)

if [[ -f /usr/sbin/kmtune ]]

then

print “Running kmtune (selective)”

print “\nOutput from kmtune (selective):\n” >> ${info_filename}

/usr/sbin/kmtune -q ksi_alloc_max -q max_thread_proc -q maxdsiz -q maxdsiz_64bit -q maxfiles -q maxfiles_lim -q maxssiz -q maxssiz_64bit -q maxswapchunks -q maxuprc -q maxusers -q msgmap -q msgmni -q msgseg -q msgtql -q ncallout > ${temp_filename_1}

/usr/sbin/kmtune -q ncsize -q nfile -q nflocks -q ninode -q nkthread -q nproc -q semmap -q semmni -q semmns -q semmnu -q semvmx -q shmmax -q shmmni -q shmseg -q vps_ceiling -q vx_ncsize >> ${temp_filename_1}

sed -e ’s/===============================================================================//’ ${temp_filename_1} > ${temp_filename_2}

sed -e ’s/Parameter Value//’ ${temp_filename_2} > ${temp_filename_1}

cat ${temp_filename_1} | sort | uniq | sed -e ‘/^$/d’ > ${temp_filename_2}

/usr/sbin/kmtune -q bufpages > ${temp_filename_1}

cat ${temp_filename_1} ${temp_filename_2} >> ${info_filename}

print “Running kmtune (long listing)”

print “\nOutput from kmtune (long):\n” >> ${info_filename}

/usr/sbin/kmtune -l >> ${info_filename}

else

print “/usr/sbin/kmtune not found”

fi

;;

SunOS)

if [[ -f /etc/system ]]

then

print “Printing system information”

print “\n\tSelected output from /etc/system:\n” >> ${info_filename}

grep set /etc/system | grep -v ‘*’ | grep -v mddb_bootlist1 | cut -d ‘ ‘ -f2 > ${temp_filename_1}

cat ${temp_filename_1} | while read line

do

print “\t${line}” >> ${info_filename}

done

rm ${temp_filename_1}

else

print “/etc/system cannot be found”

fi

print “\n” >> ${info_filename}

if [[ -x /etc/sysdef ]]

then

print “Getting kernel information – please wait”

print “\tSelected output from sysdef:\n” >> ${info_filename}

> ${temp_filename_1}

/etc/sysdef -i |sed -e ’s/*/#/g’ |while read line

do

START=`echo “${line}” |grep ‘Tunable Parameters’`

if [[ "${START}" != "" ]]

then

WRITE=”YES”

fi

if [[ "${WRITE}" = "YES" ]]

then

echo ${line} |while read first rest

do

if [[ "${first}" != "#" ]]

then

print “\t${rest}\t${first}” >> ${temp_filename_1}

fi

done

fi

done

cat ${temp_filename_1} | grep -v ‘(‘ | sort > ${temp_filename_2}

cat ${temp_filename_1} | grep ‘(‘ | sort > ${temp_filename_3}

typeset -i strsize=0

> ${temp_filename_4}

cat ${temp_filename_3} | while read line

do

field1=$(print ${line} | cut -d ‘(‘ -f1)

field2=$(print ${line} | cut -d ‘(‘ -f2 | cut -d ‘)’ -f1)

field3=$(print ${line} | cut -d ‘(‘ -f2 | cut -d ‘ ‘ -f2)

strsize=${#field2}

if [[ ${strsize} -gt 7 ]]

then

tabstr1=”"

else

tabstr1=”\t”

fi

strsize=${#field3}

if [[ ${strsize} -gt 7 ]]

then

tabstr2=”"

else

tabstr2=”\t”

fi

if [[ ${strsize} -gt 14 ]]

then

tabstr3=”"

else

tabstr3=”\t”

fi

print “\t${field2}${tabstr1}\t${field3}${tabstr2}${tabstr3}\t${field1}” >> ${temp_filename_4}

done

cat ${temp_filename_2} >> ${info_filename}

cat ${temp_filename_4} | sort >> ${info_filename}

rm ${temp_filename_1} ${temp_filename_2} ${temp_filename_3} ${temp_filename_4}

unset strsize field1 field2 field3

fi

if [[ -x /usr/bin/isainfo ]]

then

word_size=$(/usr/bin/isainfo -kv | cut -c 1-2)

if [[ ${word_size} = "64" ]]

then

if [[ -x /usr/bin/showrev ]]

then

print “Running showrev”

print “\nOutput from showrev -p:\n” >> ${info_filename}

/usr/bin/showrev -p >> ${info_filename}

else

print “/usr/bin/showrev cannot be executed by this user”

fi

else

if [[ -x /usr/bin/pkginfo ]]

then

print “Running pkginfo”

print “\nOutput from pkginfo -i package name:\n” >> ${info_filename}

/usr/bin/pkginfo -i package name >> ${info_filename}

else

print “/usr/bin/pkginfo cannot be executed by this user”

fi

fi

else

print “/usr/bin/isainfo cannot be executed by this user”

fi

;;

esac

}

f_network()

{

print “\n\nNETWORK Information” >> ${info_filename}

print “======= ===========” >> ${info_filename}

case ${op_sys} in

HP-UX)

print “Obtaining IP Address”

srvr_name=$(uname -n)

IPADDRESS=`/usr/sbin/ping ${srvr_name} -n 1|grep ^64 |sed -e ’s/(/ /g’ -e ’s/)/ /g’ -e ’s/:/ /g’ |awk ‘{print $4}’`

if [ "${IPADDRESS}" = "" ]; then

IPADDRESS=”Unknown”

fi

print “\n\tIP Address:\t\t${IPADDRESS}\n” >> ${info_filename}

unset srvr_name

f_hosts_file

if [[ -f /usr/bin/ndd ]]

then

print “Running ndd”

print “\nOutput from ndd on tcp_conn_request_max:\n” >> ${info_filename}

/usr/bin/ndd -get /dev/tcp tcp_conn_request_max >> ${info_filename}

else

print “/usr/bin/ndd not found”

fi

;;

SunOS)

print “Obtaining IP Address”

srvr_name=$(uname -n)

ipadd=$(ping -s ${srvr_name} 56 1|grep 64 | cut -d ‘ ‘ -f5)

ipaddstrsize=${#ipadd}

(( ipaddstrsize = ${ipaddstrsize} – 2 ))

dispipadd=$(echo ${ipadd} | cut -c 2-${ipaddstrsize})

if [[ "${dispipadd}" = "" ]]

then

dispipadd=”Unknown”

fi

print “\n\tIP Address:\t\t\t${dispipadd}\n” >> ${info_filename}

unset srvr_name ipadd ipaddstrsize dispipadd

f_hosts_file

;;

esac

}

f_hosts_file()

{

if [[ -f /etc/hosts ]]

then

print “\n\t/etc/hosts file contents:” >> ${info_filename}

print “\n\t\tIP Address\tHostname\tExtra information” >> ${info_filename}

print “\t\t———-\t——–\t—————–” >> ${info_filename}

grep ‘^[0-9]‘ /etc/hosts |awk ‘{print ” “$1″\t”$2″\t”$3″\t”$4″\t”$5}’ >> ${info_filename}

else

print “/etc/hosts not found”

fi

}

f_filesystem()

{

print “\n\nDATA STORAGE Information” >> ${info_filename}

print “==== ======= ===========\n” >> ${info_filename}

case ${op_sys} in

HP-UX)

if [[ -f /etc/fstab ]]

then

print “Getting contents of fstab”

print “\n\t/etc/fstab file contents:\n” >> ${info_filename}

print “\n\t\tRaw device\tMount Point\tType\tOptions\tDump\tFSCK” >> ${info_filename}

print “\t\t———-\t———–\t—-\t——-\t—-\t—-” >> ${info_filename}

egrep ‘^/|^[a-z]‘ /etc/fstab |sed -e ’s/,/;/g’ |awk ‘{print “\t\t”$1″\t”$2″\t”$3″\t”$4″\t”$5″\t”$6}’ >> ${info_filename}

else

print “/etc/fstab not found”

fi

if [[ -f /usr/bin/bdf ]]

then

print “Running bdf”

print “\n\n\tMounted Filesystem information:\n” >> ${info_filename}

/usr/bin/bdf |awk ‘{if ( NF == 1 ) {printf(“\t\t%s\t”,$1)} else {for (i = 1; i <= NF-1; i++) {printf(“\t\t%s\t”,$i)} i++; print $NF } }’ >> ${info_filename}

else

print “/usr/bin/bdf not found”

fi

;;

SunOS)

if [[ -f /etc/vfstab ]]

then

print “Getting contents of vfstab”

print “\n\t/etc/vfstab file contents:\n” >> ${info_filename}

print “\n\t\tRaw device\tMount Point\tType\tOptions\tDump\tFSCK” >> ${info_filename}

print “\t\t———-\t———–\t—-\t——-\t—-\t—-” >> ${info_filename}

egrep ‘^/|^[a-z]‘ /etc/vfstab |sed -e ’s/,/;/g’ |awk ‘{print “\t\t”$1″\t”$2″\t”$3″\t”$4″\t”$5″\t”$6}’ >> ${info_filename}

else

print “/etc/vfstab not found”

fi

if [[ -x /usr/bin/df ]]

then

print “Running df”

print “\n\n\tMounted Filesystem information:\n” >> ${info_filename}

/usr/bin/df > ${temp_filename_1}

cat ${temp_filename_1} | while read line

do

print “\t\t${line}” >> ${info_filename}

done

rm ${temp_filename_1}

else

print “/usr/bin/df not executable by this user”

fi

;;

esac

}

f_3rd_party()

{

case ${supplied_parameter} in

n)

# Do nothing

;;

o)

# Search only for Oracle

print “\n\n3RD PARTY SOFTWARE Information” >> ${info_filename}

print “=== ===== ======== ===========\n” >> ${info_filename}

f_find_oracle

;;

j)

# Search only for Java

print “\n\n3RD PARTY SOFTWARE Information” >> ${info_filename}

print “=== ===== ======== ===========\n” >> ${info_filename}

f_find_java

;;

*)

# Search for Java and Oracle

print “\n\n3RD PARTY SOFTWARE Information” >> ${info_filename}

print “=== ===== ======== ===========\n” >> ${info_filename}

f_find_oracle

f_find_java

;;

esac

}

f_find_java()

{

if [[ "${JAVA_HOME}" != "" ]]

then

> ${temp_filename_1}

java -version 2>&1 | tee ${temp_filename_1}

java_version=$(grep version ${temp_filename_1})

disp_java=$(print ${java_version} | cut -c 6-${#java_version})

print “\n\tJava installed is ${disp_java}\n” >> ${info_filename}

unset disp_java

else

print “Trying to find Java – please wait”

> ${temp_filename_1}

print “#! /bin/ksh” > ${temp_filename_4}

print “find / -name java -print > ${temp_filename_1} 2>/dev/null” >> ${temp_filename_4}

chmod 750 ${temp_filename_4}

./${temp_filename_4} |&

ps_line=$(ps -ef|grep find | grep java)

the_pid=$(echo ${ps_line} | cut -d ‘ ‘ -f2)

unset ps_line

while true

do

print -n — .

sleep 1

if [ `ps -ef | grep ${the_pid} | grep java | wc -l` -eq 0 ]

then

print

break

fi

done

cat ${temp_filename_1} | grep jre | grep bin | grep -v oracle | grep -v openv | grep -v PA_RISC > ${temp_filename_2}

typeset -i file_count=$(wc -l ${temp_filename_2} | cut -d ‘ ‘ -f1)

if [ ${file_count} -gt 0 ]

then

print “\n\tJava found at:” >> ${info_filename}

cat ${temp_filename_2} >> ${info_filename}

else

print “\n\tNo versions of Java were found” >> ${info_filename}

fi

unset file_count

unset the_pid

fi

}

f_find_oracle()

{

if [[ "${ORACLE_HOME}" != "" ]]

then

> ${temp_filename_1}

sqlplus -version > ${temp_filename_1}

disp_ora=$(grep ‘[0-9]‘ ${temp_filename_1} | cut -d ‘ ‘ -f3)

print “\n\tOracle installed is version ${disp_ora}\n” >> ${info_filename}

unset disp_ora

if [ `ps -ef | grep tnslsnr | grep -v grep | wc -l` -eq 1 ]

then

if [ -x ${ORACLE_HOME}/bin/lsnrctl ]

then

print “\n\t\tListener status:\n” >> ${info_filename}

${ORACLE_HOME}/bin/lsnrctl status > ${temp_filename_4}

cat ${temp_filename_4} | grep Instance | grep READY | uniq | sort | sed -e ’s/Instance/ Instance/’ | sed -e ’s/for this service…//’ >> ${info_filename}

cat ${temp_filename_4} | grep Instance | grep UNKNOWN | uniq | sort | sed -e ’s/Instance/ Instance/’ | sed -e ’s/for this service…//’ >> ${info_filename}

fi

fi

else

print “Trying to find Oracle – please wait”

> ${temp_filename_1}

print “#! /bin/ksh” > ${temp_filename_4}

print “find / -name oracle -print > ${temp_filename_1} 2>/dev/null” >> ${temp_filename_4}

chmod 750 ${temp_filename_4}

./${temp_filename_4} |&

ps_line=$(ps -ef|grep find | grep oracle)

the_pid=$(echo ${ps_line} | cut -d ‘ ‘ -f2)

unset ps_line

while true

do

print -n — .

sleep 1

if [ `ps -ef | grep ${the_pid} | grep oracle | wc -l` -eq 0 ]

then

print

break

fi

done

cat ${temp_filename_1} | grep bin | grep -v java | grep -v ultrasearch > ${temp_filename_2}

typeset -i file_count=$(wc -l ${temp_filename_2} | cut -d ‘ ‘ -f1)

if [ ${file_count} -gt 0 ]

then

print “\n\tOracle found at:” >> ${info_filename}

cat ${temp_filename_2} >> ${info_filename}

else

print “\n\tNo versions of Oracle were found” >> ${info_filename}

fi

unset the_pid

unset file_count

fi

}

f_terminate()

{

print “\n\n\t\t\t\t############”

print “\t\t\t\t# FINISHED #”

print “\t\t\t\t############\n”

XX=`date “+%a %d %b %Y %X %Z”`

print “\n${XX}” >> ${info_filename}

rm -f ${temp_filename_1}

rm -f ${temp_filename_2}

rm -f ${temp_filename_3}

rm -f ${temp_filename_4}

}

#———————————————————————-

# Main

#———————————————————————-

op_sys=$(uname -s)

case ${op_sys} in

HP-UX)

;;

SunOS)

;;

*)

print “Unsupported Operating system”

exit 1

;;

esac

if [ "${1}" != "" ]

then

supplied_parameter=${1}

if [ "${supplied_parameter}" = "f" ]

then

print “\nusage: $0 [j|n|o]“

print “\t\tj=show only Java information”

print “\t\tn=do not show 3rd Party Product information”

print “\t\to=show only Oracle information”

exit 0

fi

else

supplied_parameter=”"

fi

f_initialise

f_hardware

f_operating_system

f_kernel

f_network

f_filesystem

f_3rd_party

f_terminate

exit 0

Categories: Shell Scripts

Menu Scripts

EXTRACT_LOC=/apps

check_option()
{
        echo “#———————————————#”
        echo “# AN INVALID OPTION WAS SELECTED … EXITING  #”
        echo “#———————————————#”
        exit 1
}

 

#——————————#
# Do various init processes    #
#——————————#
clear

#—————————-#
# firstly rewind the tape    #
#—————————-#
echo “script initialising …. please wait ….”
mt -f /dev/rmt/0n rewind

echo “—————————————————————”
echo “                 BACKUP MODULE SELECT PROMPT “
echo “—————————————————————”

CNT=0
while [ 1 ]
do
        CNT=`expr $CNT + 1`
        BNAME=`tar -tvf /dev/rmt/0n | awk ‘{print $8}’ | \
                              sed -e “s/\./ /g” | \
                              awk ‘{print $1}’`

        BLOCK_DATA=`echo “$BNAME” | grep -i “WIT”`
        if [ "$BLOCK_DATA" = "" ];then
                break
        fi

        #
        # add the number of the item to the description on
        # the tape
        #
        echo “*- $CNT – $BNAME”
done

echo “—————————————————————”
echo ” Please select the backup number you would like to restore     “
echo “—————————————————————”
printf “LCMG_RESTORE>>: “
read OPT

#——————————————#
# check that the option entered is valid   #
#——————————————#
VALIDITY=`echo “$OPT” | grep [1-$CNT]`
if [ "$VALIDITY" = "" ];then
        check_option
fi

echo
echo “—————————————————————”
echo “                 SERVER RESTORE SELECT PROMPT”
echo “—————————————————————”
echo ” *-1 cs01cwbp-oam                  (Wirless Broker 1)”
echo ” *-2 cs02cwbp-oam                  (Wirless Broker 2)”
echo ” *-3 cs01cvgp                      (VAS GATEWAY -  1)”
echo ” *-4 cs02cvgp                      (VAS GATEWAY -  2)”
echo “—————————————————————”
echo
echo “—————————————————————”
echo ” Please select the host that this backup should be restored to “
echo “—————————————————————”
printf “LCMG_RESTORE>>: “
read hostid

#——————————————#
# check that the option entered is valid   #
#——————————————#
VALIDITY=`echo “$hostid” | grep [1-4]`
if [ "$VALIDITY" = "" ];then
        check_option
fi

#—————————————–#
# SELECT THE HOST WE ARE RESTORING TO     #
#—————————————–#

if [ $hostid -eq 1 ];then
        HOST=cs01cwbp-oam
fi
if [ $hostid -eq 2 ];then
        HOST=cs02cwbp-oam
fi
if [ $hostid -eq 3 ];then
        HOST=cs01cvgp
fi
if [ $hostid -eq 4 ];then
        HOST=cs02cvgp
fi

#————————————————–#
# now rewind the tape and find the correct record  #

#————————————————–#
# now rewind the tape and find the correct record  #
#————————————————–#
echo “tape initialising & searching please wait ….”
mt -f /dev/rmt/0n rewind

LCNT=1
DOT=”…”; printf “|”
while [ 1 ]
do
        printf “$DOT”
        if [ $LCNT -eq $OPT ];then
                printf “|”
                #——————————————#
                # Above is simply for the progress looks   #
                #——————————————#
                echo
                EXTRACT_FNAME=`tar -xvf /dev/rmt/0n | awk ‘{ print $2 }’| sed -e “s/\,//g”`
                #——————————————#
                # extraction occuring above                #
                #——————————————#
                echo
                echo “     …-{EXTRACTION OF BACKUP FILE COMPLETE}-…    “
                echo
                echo ” EXTRACTED FILE: $EXTRACT_FNAME”
                break
        fi
        LCNT=`expr $LCNT + 1`
        mt -f /dev/rmt/0n fsr
        DOT=”$DOT…”
done

#—————————————-#
# copy the data to the required server   #
#—————————————-#
scp -p $EXTRACT_FNAME $HOST:$EXTRACT_LOC

#
# ssh -l root $HOST “cd / ; gunzip $EXTRACT_FNAME ; tar -xvf $EXTRACT_FNAME”

Categories: Shell Scripts