Host common is a library of functions that will help to create, maintain, hosts involved with Oracle databases as well as other types of servers

This file should also have the

List of functions

HSTCREATE => hst_common.ksh
HSTCREATE - Library of creation scripts for creating and maintaining hosts
Linux_common.ksh should be used in this capacity to link in the necessary low-level scripts to perform

/oracle/admin/scripts/hstcreate - current production copy of the scripts
/oracle/admin/scripts/hstcreate/dev - development stuff

Using DBAdmin there are several functions that can be utilized for these purposes

hst_create.ksh -

initapex()
{

}

This function shows the banner of the script and the script name along with the arguments file
disp_banner_hst_cr ()
{
echo
echo "Host create script..........: hst_create.ksh"
echo "Host create arguments file..: hst_create.args"
echo
}


function next_menu
{
echo
echo "# ----------------------------------------------------------------------- #"
echo "[ ...  Press any key to continue ... ]"
read next
}

init_apex ()
{

# Initialize the database access to DBAdmin
# Set this up on a separate database
export BRAIN1D='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=49125))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DBADMD01)))'
export DBADM='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=49125))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DBADMD01)))'
export DBADM42='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=49125))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=BRAIN1D)))'

export UsrPwd='hc_core/somepassword'
export UsrPwd2='dba01/somepassword'

}

host_apex_chk ()
{
####################################################################
# prereq is init_apex function should be included
# Set the hostname then search for the host record in APEX
# once you get the DBAdmin host record in mach_id
####################################################################
# grab the hostname
hst_nm=`hostname`

# echo $hst_nm
mach_id=`${ORACLE_HOME}/bin/sqlplus -s $UsrPwd2@$BRAIN1D <<EOF
        set head off feed off pages 0 trimspool on
        select MCH_ID from dba01.machine where MCH_NM=upper('$hst_nm');
--        select MCH_ID from dba01.machine;
--        exit;
EOF`

mch_nm=`${ORACLE_HOME}/bin/sqlplus -s $UsrPwd2@$BRAIN1D <<EOF
        set head off feed off pages 0 trimspool on
        select MCH_NM from dba01.machine where MCH_NM=upper('$hst_nm');
--        exit;
EOF`

# Uncomment the next line for debugging purposes
# echo "DBAdmin record no...: "$mach_id

}


This is a directory checking function, if the directory doesn't exists it creates it

chk_gen_dir ()
{
############################################################################
# Check to see if the directory to generate the files exists
# added /scripts to the end of the gendir to check
############################################################################
if [ ! -d $gendir/scripts ] ; then
#   echo "Directory "${gendir}" does not exist"
   print "\nDirectory ${gendir}/scripts does not exist"
   print "\nDirectory ${gendir}/scripts needs to be created "
   ans=
   while [ -z $ans ]
   do
      echo -n "Create directory? ${gendir}/scripts "
      read ans
   done
   if [[ $ans =~ ^[Yy]$ ]]
   then
      print "\n...Creating directory...."
#      mkdir ${gendir}/scripts
#      mkdir ${gendir}/scripts
      print "\n...Not Creating directory in test mode...."
   else
      print "\n...Not Creating directory...."
      print "\nExiting program"
      exit
   fi
else
   print "\nDirectory ${gendir}scripts exists"
   echo
   ls ${gendir}/scripts

   ans=
   while [ -z $ans ]
   do
      echo -n "Do you wish to overwrite what is already generated? "
      read ans
   done

   if [[ $ans =~ ^[Yy]$ ]]
    then
      print "\n...Continuing..............................."
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi

   ans=
   while [ -z $ans ]
   do
      echo -n "Proceed to script creation? "
      read ans
   done

   if [[ $ans =~ ^[Yy]$ ]]
    then
      print "\n............................................"
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi

fi


if [ ! -d $gendir/logs ] ; then
#  echo "Directory "${gendir}/logs" does not exist"
   print "\nDirectory ${gendir}/logs does not exist"
   print "\nDirectory ${gendir}/logs needs to be created "
   ans=
   while [ -z $ans ]
   do
      echo -n "Create directory? ${gendir}/logs "
      read ans
   done
   if [[ $ans =~ ^[Yy]$ ]]
   then
      print "\n...Creating directory...."
#      mkdir ${gendir}/logs
#      mkdir ${gendir}/logs
      print "\n...Not Creating directory in test mode...."
   else
      print "\n...Not Creating directory...."
      print "\nExiting program"
      exit
   fi
else
   print "\nDirectory ${gendir}/logs exists"
   echo
   ls ${gendir}/logs

   ans=
   while [ -z $ans ]
   do
      echo -n "Do you wish to overwrite what is already generated? "
      read ans
   done

   if [[ $ans =~ ^[Yy]$ ]]
    then
      print "\n...Continuing..............................."
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi

   ans=
   while [ -z $ans ]
   do
      echo -n "Proceed to script creation? "
      read ans
   done

   if [[ $ans =~ ^[Yy]$ ]]
    then
      print "\n............................................"
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi

fi

pauseit
clear
}




cr_hst_crontab ()
{
############################################################################
# Create the crontab entries
############################################################################

echo "...Creating crontab file entries......."
echo > crontab_${db_assn_name}.txt
cat << EOS >> crontab_${db_assn_name}.txt
Text goes here
EOS
}


cr_sysctl ()
{
echo "...Creating sysctl.conf recommendations......."
####################################################################################################
# Create the cr_<database name>_dbca.ksh script /oracle/admin/scripts/rspfiles
####################################################################################################
# echo > cr_${host_name}_sysctl.ksh
cat << EOS > cr_${host_name}_sysctl.conf
#!/bin/ksh
############################################################################
# Script Name..:
# Description..:
# Author.......: $auth
# Date.........: $use_date
# Version......:
# Modified By..:
# Date Modified:
# Comments.....:
# Schema owner.:
#              : alter session set current should be used to change schemas
# Login User...:
# Run Order....:
# Dependent on.:
# Script type..:
############################################################################

# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 1

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 1

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.log_martians = 0
net.ipv4.conf.default.log_martians = 0
net.ipv4.tcp_keepalive_time = 3600
kernel.panic_on_oops = 1
kernel.panic = 5
#ORACLE CONFIG
#fs.aio-max-nr = 1048576
fs.aio-max-nr = 3145728
kernel.shmmax = 17179869184
kernel.shmmni = 4096
kernel.shmall = 8388608
#kernel.sem = 250 32000 100 128
kernel.sem = 250 64000 100 256
net.core.rmem_default = 4194304
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4194304 4194304 4194304
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.ip_local_port_range = 1024 65000
vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 15
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
vm.hugetlb_shm_group = 0
vm.nr_hugepages = 2048
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744

EOS

# Move previous file to the correct directory
# cp cr_${db_assn_name}_dbca.ksh /oracle/admin/scripts/rspfiles

}


ck_cls ()
{

############################################################################
# This will check the cluster
############################################################################

if [[ "$database_id" = "Database Not In APEX" ]]; then
   ans=
   while [ -z $ans ]
   do
      echo
      echo -n "Add database record to APEX? "
         read ans
   done
   if [[ $ans =~ ^[Yy]$ ]]
   then
      echo
      print "\n....Adding APEX database record....."

${ORACLE_HOME}/bin/sqlplus -s $UsrPwd2@$BRAIN1D <<EOF
      insert into dba01.database
         (DB_ID,
          DB_NM,
          DB_DSCR,
          DB_CRT_DT,
          DB_UNQ_NM)
      values
         (DB_ID.NEXTVAL,
          '$db_assn_name',
          'Database added by DBAdmin ddl_create please update columns ',
          sysdate,
          '$db_assn_nm');
      commit;
EOF
      print "\n....APEX database record added....."
database_id=`${ORACLE_HOME}/bin/sqlplus -s $UsrPwd2@$BRAIN1D <<EOF
        set head off feed off pages 0 trimspool on
        select DB_ID from dba01.database where DB_NM='$db_assn_name';
        exit;
EOF`
        echo $database_id
   else
      echo
      print "\n....Continuing without adding record to APEX........."
      # exit
   fi
fi


# Check to see if the directory to generate the files exists
############################################################################
if [ ! -d $gendir ] ; then
   print "\nDirectory ${gendir} does not exist"
   print "\nDirectory ${gendir} needs to be created "
   ans=
   while [ -z $ans ]
   do
      echo -n "Create directory? ${gendir} "
      read ans
   done
   if [[ $ans =~ ^[Yy]$ ]]
   then
      print "\n...Creating directory...."
      mkdir ${gendir}
      mkdir ${gendir}/scripts
   else
      print "\n...Not Creating directory...."
      print "\nExiting program"
      exit
   fi
else
   print "\nDirectory ${gendir} exists"
   echo
   ls ${gendir}/scripts

   ans2=
   while [ -z $ans2 ]
   do
      echo -n "Do you wish to overwrite what is already generated? "
      read ans2
   done

   if [[ $ans2 =~ ^[Yy]$ ]]
    then
      print "\n...Continuing..............................."
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi


   ans2=
   while [ -z $ans2 ]
   do
      echo -n "Proceed to script creation? "
      read ans2
   done

   if [[ $ans2 =~ ^[Yy]$ ]]
    then
      print "\n............................................"
   else
      print "\n....Exiting program without creating scripts"
      exit
   fi

fi

gendir=${gendir}/scripts

echo " "
echo " "


# You can bale out here for whatever reason
#########################################################################
ans=
while [ -z $ans ]
do
   echo -n "Really Proceed with script creation ? "
      read ans
done
if [[ $ans =~ ^[Yy]$ ]]
then
   print "\n....Creating scripts....."
else
   print "\n....Exiting program without creating scripts"
   exit
fi
############################################################################

############################################################################
# Create the directory /oracle/admin/<database name>/scripts
#
# Create the directory for this to all go into
# mkdir -p /oracle/admin/$db/scripts
# mkdir -p /oracle/admin/$db/scripts/logs
# cd /oracle/admin/scripts/mrc/ddltest/$appabrl
# /oracle/admin/scripts/mrc/ddltest/testddlcr
############################################################################

print "\n.....Changing to directory ${gendir} "
cd ${gendir}
}



cr_tmplt ()
{
echo "...Creating template file......."
# Create the
############################################################################
echo > template.ksh
cat << EOS >> template.ksh

EOS
}

function next_menu
{
echo
echo "# ----------------------------------------------------------------------- #"
echo "[ ...  Press any key to continue ... ]"
read next
}

Ready for Action?

LET'S GO!
Copyright 2024 IT Remote dot com
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram