It is currently Tue, 07 Dec 2021 01:42:54 GMT



 
Author Message
 Call function within a function
Below is a script I have written.

The CISCHECK function is the question I have. It checks a file placed
there by another process on another server to see if  the app should
continue.

Script runs fine. However in the CISCHECK code I have been asked to
look for this file 5 times before I  abort the script via exit.

I would like to know if I place a while do done sequence  while x != 0
 inside the if  construct and call CISCHECK each time the files don't
match with a sleep between each call how would the calling of a
function within a function work.

Question is are recursive calls within a function allowed. I suppose I
could put the entire CISCHECK function inside a while loop and break
out if needed.

xx:oracle>ods
/u01/app/oracle/admin/scripts
agasc38u:oracle>cat morsimp.ksh
#! /bin/ksh  
#Name     - morsimp.ksh            
#Author   - James A. Williams        
#Date     - 05/17/2002
#Purpose  - driver of the MORS import      
#Invoke   - from shell  morsimp.ksh SID  email age step keepfile  
#           morsimp.ksh AXX1 jwill...@aglresources.com 7 2        
would run against ADD1 with 7 dayold morsfile starting at ORACHx
#           $1= SID
#           $2= Days since last run.
#           $3= email address.
#           $4= restart number       0 1 2 3 4 5
#           $5= check to see if target mors file is already good

###############################################################################
#                                                                    
       #
#  This script will copy the MORS export created during the MORS load
       #
#  process to the target machine and then  import it to the target
database   #
#  on the local machine.                                              
       #
#                                                                    
       #
###############################################################################

#    arguments   as noted above

if [ -z "$1" ]
 then                                        
         echo "supply name of the Oracle SID"            
         exit 2
fi

if [ -z $2  ]
 then
        echo "did not specify number of days old for archive"
        exit 2
fi

if [ -z $3  ]
 then
        echo "Must specify e-mail addresses(s)"
        exit 2
fi

if [ -z $4  ]
 then
        echo "allows for restart processing if nessacary"
        echo "0=CISCHECK  - CIS is up"
        echo "1=HACHECK   - is HA up"
        echo "2=ORACHECK  - is $1 instance up"
        echo "3=MORSCHECK - is it the right file"
        echo "4=RCPCHECK  -  get file over to target"
        echo "5=MORSIMP   -  do the actual import"
        echo "Defaults to beginning if no selection"
fi

if [ -n $5  ]
 then
        echo "The MORS RCP process will take place"
        echo "Normal RCP process if RCPCHECK not passed"
 else
        echo "Will check to see if RCP process needed"
        echo "if not step bypassed"
fi

#     Set up Environment
ORACLE_ADMIN=/u01/app/oracle/admin
export ORACLE_ADMIN
. $ORACLE_ADMIN/scripts/morsimp.setup
#     End of setup

#                      
# Beginning of sub routine code
#                      

function CISCHECK {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo "#"                    
echo "#  check for for CICS region up on agasc01m"
echo "#  will try x number of times              "
echo "#"                    
echo " "                    

if [[ ! -a ${ADIR}/${UFILE} ]]
 then
   echo  "$ADIR/$DFILE not found CICS may not be up" >> ${OUTPUT}
   echo "CICS not up on agasc01m" >> ${OUTPUT}
   echo "EMAIL or Page is needed needed" >> ${OUTPUT}
   echo "Must be up to do MORS load" >> ${OUTPUT}
   echo "`date` on `uname -n`" >> ${OUTPUT}
   mailx -s "MORSIMP stopped CICS down $SID `uname -n`" ${MAILADDR} <
${OUTPUT}
   exit 2
fi

if [[ ! -a ${ADIR}/${DFILE} ]]
 then
   echo  "$ADIR/$DFILE not found continue on CICS is up" >>  ${OUTPUT}
   echo  "Continue to next check" >> ${OUTPUT}          
   return 0
fi

find $ADIR/$UFILE -mtime -$AAGE  -exec ls -lt {} \; > ${TESTER}
STIME=`cat $TESTER | awk '{print $7$8 "\t" }'`
STIME=`echo $STIME | awk -F: '{print $1$2 "\t" }'`
find $ADIR/$DFILE -mtime -$AAGE -exec ls -lt {} \; > ${TESTER}
ETIME=`cat $TESTER | awk '{print $7$8 "\t" }'`
ETIME=`echo $ETIME | awk -F: '{print $1$2 "\t" }'`

if [ ${ETIME} -gt ${STIME} ]
     then
          echo "CICS not up on agasc01m" >> ${OUTPUT}
          echo "$ETIME GT $STIME for $DFILE vs. $UFILE" >> ${OUTPUT}
          echo "EMAIL or Page is needed needed" >> ${OUTPUT}
          echo "Must be up to do MORS load" >> ${OUTPUT}
          echo "`date` on `uname -n`" >> ${OUTPUT}
          mailx -s "MORSIMP stopped CICS down $SID `uname -n`"
${MAILADDR} < ${OUTPUT}
          exit 2
fi
return 0

function HACHECK {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo "#"                    
echo "#  check for ha_oracle if up leave and page"
echo "#"                    
echo " "                    

ps -ef | grep "haoracle" | grep -v "grep" >> ${OUTPUT}

grep "haoracle" ${OUTPUT}

  if [[ "$?" -eq 0 ]]
     then
          echo "For $SID HAORACLE is up on `uname -n`" >> ${OUTPUT}
          echo "EMAIL or Page is needed needed" >> ${OUTPUT}
          echo "Must be down to do MORS load" >> ${OUTPUT}
          echo "`date` on `uname -n`" >> ${OUTPUT}
          mailx -s "MORSIMP stopped HA up $SID `uname -n`" ${MAILADDR}
< ${OUTPUT}
          exit 2
  fi
return 0

function ORACHECK {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo "#"                    
echo "#  check for $SID if down leave and page"
echo "#"                    
echo " "                    

ps -ef | grep "ora_pmon_$SID" | grep -v "grep" >> ${OUTPUT}

grep "ora_pmon_$SID" ${OUTPUT}

  if [[ "$?" -ne 0 ]]
     then
          echo "$SID is not up on `uname -n`" >> ${OUTPUT}
          echo "EMAIL or Page is  needed " >> ${OUTPUT}
          echo "`date` on `uname -n`" >> ${OUTPUT}
          mailx -s "MORSIMP stopped $SID not up on `uname -n`"
${MAILADDR} < ${OUTPUT}
          exit 2
  fi
return 0

function MORSCHECK {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo " "                    
echo "#"                    
echo "#  check for proper version of $RBOX:/$RDIR/$RFILE"
echo "#"                                
echo " "                    

rsh $RBOX ls -lt $RDIR/$RFILE >> ${OUTPUT}
rsh $RBOX "find $RDIR/$RFILE -mtime -$RAGE -exec ls -lt {} \;" >
${TESTER}
cat $TESTER | awk '{print $5 "\t" }' > ${RTEST}    

grep "$RFILE" ${TESTER}

  if [[ "$?" -ne 0 ]]
     then
          echo "$RDIR/$RFILE  is not on $RBOX at right version" >>
${OUTPUT}
          echo "EMAIL or Page  needed" >> ${OUTPUT}
          echo "`date` on `uname -n`" >> ${OUTPUT}
          mailx -s "MORSIMP stopped $RFILE downlevel on `uname -n`"
${MAILADDR} < ${OUTPUT}
          exit 2
  fi

echo " "                    
echo "#"                    
echo "#  check complete of RCP"
echo "#"                    
echo " "                    

return 0

function RCPCHECK {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo "#"                    
echo "#  RCP process of remote to local beginning `date` "
echo "#  FROM                        $RBOX:/$RDIR/$RFILE"
echo "#  To                          $TBOX:/$TDIR/$TFILE"
echo "#"                                
echo " "                    

echo "#"                                
echo "#Value for TAGE=$TAGE"
echo "#If blank the RCP will continue"
echo "#"                                
echo " "                    

if [ -n "$TAGE"  ]      
  then
    find $TDIR/$TFILE -mtime -$TAGE -exec ls -lt {} \; > ${TESTER}
    echo "It was determined that we should try to use file on the
local server based on $TAGE being set"
    grep "$TFILE" ${TESTER}            
    cat $TESTER | awk '{print $5 "\t" }' > ${LTEST}    
    diff $LTEST $RTEST  >> ${OUTPUT}

     if [[ "$?" -eq 0 ]]
       then
          echo "$RDIR/$RFILE  on  $RBOX  matches with  completeness"
          echo "$TDIR/$TFILE  on  $TBOX with  completeness" >>
${OUTPUT}
          echo "Skip rest of RCP and goto import          " >>
${OUTPUT}
          echo "`date` on `uname -n`" >>  ${OUTPUT}
          return 0
       else
          echo "It was determined that we copy the file onto the local
server based on TAGE being set" >> ${OUTPUT}
          echo "$TDIR/$TFILE on  $TBOX -NE $RDIR/$RFILE on $RBOX" >>
${OUTPUT}
          echo "Continue on with RCP" >> ${OUTPUT}    
       fi

  fi

echo ""                            
echo "It was determined that we copy the file onto the local server"
echo "RCP Begins"     >> ${OUTPUT}    
echo ""                            
rm   $TDIR/$TFILE     >>   ${OUTPUT}
rcp  $RBOX:$RDIR/$RFILE  $TBOX:$TDIR/$TFILE  >> ${OUTPUT}
ls -lt $TDIR/$TFILE  > ${TESTER}
ls -lt $TDIR/$TFILE  >> ${OUTPUT}
grep "$TFILE" ${TESTER}            
cat $TESTER | awk '{print $5 "\t" }' > ${LTEST}    

diff $LTEST $RTEST  >> ${OUTPUT}

if [[ "$?" -ne 0 ]]
     then
          echo "$RDIR/$RFILE  is not copied from  $RBOX with
completeness" >> ${OUTPUT}
          echo "$TDIR/$TFILE  is not copied to    $TBOX with
completeness" >> ${OUTPUT}
          echo "EMAIL or Page  needed" >> ${OUTPUT}
          echo "`date` on `uname -n`" >>  ${OUTPUT}
          mailx -s "MORSIMP stopped $RBOX to $TBOX on `uname -n`"
${MAILADDR} < ${OUTPUT}
          exit 2
 fi

echo "#"                    
echo "#  RCP process of remote to local ended  succesfully `date` "
echo " "                    
return 0

function MORSIMPR  {
case $M_TRACE in
    T) set -x
       ;;
  esac

echo "#"                    
echo "#  begining of MORS import process `date` "
echo "#  All previous checks successful  `date` "
echo "#"                    
echo " "                    

cd $MORSDIR
drop_import_special_master >> ${OUTPUT}  2> ${OUTPUTL}
cat ${OUTPUTL} >> ${OUTPUT}

grep   ORA-  ${OUTPUT}

if [[ "$?" -eq 0 ]]
...

read more »



 Mon, 15 Nov 2004 04:26:16 GMT   
 Call function within a function
"James A. Williams" <jwill...@aglresources.com> wrote

Works just fine.  A function calling a function is no different
than a function "calling" a command.

Yes.  But recursion is not necessary here.

[snip]

I like your 1st idea, have CISCHECK call a helper function,

  function file_exists {
  typeset -i cnt=0
  while : ; do
    [[ -a $1 ]] && return 0
    (( ++cnt == 5 )) && break
    sleep 2
  done
  # not found
  return 1
  }

Use this helper function by deleting this line,

And calling the helper function instead,

  if ! file_exists ${ADIR}/${UFILE}

[snip]

--
David Thompson
dat1...@yahoo.com



 Mon, 15 Nov 2004 05:48:43 GMT   
 
   [ 2 post ] 

Similar Threads

1. how to know the instruction address of calling function within called function?

2. Browser calls CGI C function which sets an env var and call a c function crashes

3. Need Help calling variable within function

4. Main function calling another main function

5. C functions calling C++ functions on Solaris

6. function calls versus function pointers ?

7. Tree of Functions calling Functions etc.

8. Non-__init functions calling __init functions

9. function, function...who's got the function?

10. Need utility to trap network function calls (socket calls) and save to log file


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software