Sponsored Content
Top Forums Shell Programming and Scripting Unable to obtain the desired output Post 302837019 by brinjit on Thursday 25th of July 2013 04:23:11 AM
Old 07-25-2013
Unable to obtain the desired output

Hi,

I made the necessary changes but still not able to go beyond the exit function:

Code:
 
#!/usr/bin/ksh
#########################################################################
#  script name: cdg_file_load_test.ksh
#  Created    : July 25, 2013
#  Author     : Brinjit Velu
#
#  Find new files for the file type and period that is passed in in the form
#       of a lookup key that is used to determine what directory and file masks
#       to look for. The lookup file is $FP_ENV/CDG_Lookup.txt
#
#  Revision History: (include date, username, and brief description in
#     descending order)
#########################################################################
#
#  Function definitions
#
#  Usage Function
#
function usage_msg {
   echo "\n---> Usage: \n"
   echo "---> cdg_file_load_test.ksh -k< key > "
        echo "          -k is a Key lookup value in the $FP_ENV/CDG_Lookup.txt file."
#       grep -v "#"  $lookupFile | cut -d"|" -f1 | sort | uniq
        echo ""
   exit_func
}
#
#  Exit Function
#
function exit_func {
   echo "---> Running exit function..."
         if [ $? -ne 0 ]
              then 
                                  update_job_table
         
         fi
        
   exit $rc
         #  update_job_table only when $rc != 0
}
#
#   Make sure the file is static
#
function is_file_changing {
        baseName=`basename ${sourceFile}`
        timeFile=${FP_LOGDIR}/${baseName}_tmstp
        touch ${timeFile}
        echo "Time Compare file is ${timeFile}"
        echo "---> Sleeping to see if file changes in 20 seconds "
        sleep 20 
        while [ ${sourceFile} -nt ${timeFile} ]
        do  
                touch ${timeFile}
                echo "-> Sleeping 20 more seconds...attempt $i"
                sleep 20 
                let i=$i+1
                if [ $i -gt 60 ] #  I am sick of waiting
                then
                        rc=24
                        exit_func
                fi
        done
        echo "---> File is found and not changing. "
}
#
#       Execute Informatica workflow to load new file.
# 
function load_file {
        #
        #   Determine that file is not changing.
        #
        # TEST is_file_changing
        #
        #    Creat link to file, much quicker than copying to local name.
        #
        if [ -f ${FP_FTP_DOWN}/${staticFile} or -h  ${FP_FTP_DOWN}/${staticFile} ]
        then
                rm  ${FP_FTP_DOWN}/${staticFile}  # no need to check return code, the ln command will fail.
        fi
        echo "---> Creating link from static file name ${staticFile} "
        ln -s  ${sourceFile} ${FP_FTP_DOWN}/${staticFile} 
        rc=$?
        if [ $rc -ne 0 ]
        then
                echo "---> ERROR: Unable to create link. "
                rc=30
                exit_func
        fi
        #
        #   Execute Informatica workflow
        #
        export parmFile=${FP_PARMFILES}/${workFlow}.par
        echo "---> Executing Informatica workflow ${workFlow} "
cmd="pmcmd startworkflow -wait -sv ${FP_SERVICE} -d ${FP_DOMAIN} -uv FP_INF_USER -pv FP_INF_PSWD " 
cmd=$cmd" -paramfile ${parmFile} -f ${FP_FOLDER} ${workFlow} "
echo "--> Command: $cmd"
  $cmd
  rc=$?
  if [ $rc -ne 0 ]
  then
                echo "---> ERROR: Error executing Informatica Workflow."
                rc=30
                exit_func
        fi
}
#
#   Determine if this file has been loaded already.
#
function has_file_been_loaded {
        alreadyLoaded=0 # False - File has not been loaded
        cnt=`grep -c ${sourceFile} ${cdgFileList}` 
        if [ $cnt -eq 0 ]
        then
                echo "---> This file has not been loaded "
        else
#               echo "---> This file has already been loaded "
                alreadyLoaded=1 
        fi
}
#
#   Check for files in a directory
#
#   More like, process a file mask for a directory for a workflow. Several file types
#        can be found in each directory, but must be processed by a different Informatica
#        workflow.
#
function process_a_directory {
        echo "Checking ${FP_CDG_CFR}${searchPath}/${searchMask}"
#       for sourceFile in `ls -1 ${FP_CDG_CFR}${searchPath}/${searchMask}*`
        for sourceFile in `find ${FP_CDG_CFR}${searchPath} -name "${searchMask}" -type f -mtime -5`
        do
                echo "---> Checking $sourceFile "
                has_file_been_loaded
                if [ ${alreadyLoaded} -eq 0 ]
                then
                        function update_job_table { 
                        # for Jeff to add later  update_job_table
                        load_file
                        let fileCntr=$fileCntr+1
                        echo $sourceFile >> ${cdgFileList} # So we won't load it again
                        #  for Jeff to add later update_job_table
                }
                fi
        done
}
#
#    extract values from lookup record
#
function get_values {
        #  Extract values 
        searchPath=`echo $rec | cut -d"|" -f2`
        searchMask=`echo $rec | cut -d"|" -f3`
        staticFile=`echo $rec | cut -d"|" -f4`
        workFlow=`echo $rec | cut -d"|" -f5`
        # Display values
        echo "\n---> Search Path = $searchPath"
        echo "---> Search Mask = $searchMask"
        echo "---> Static File = $staticFile"
        echo "---> Workflow    = $workFlow"
}
#
#   Find new files and load them
#
function find_and_load_new_files {
        echo "---> attempting to process $keyValue "
        lookupValuesFound=0
        for rec in `grep "^${keyValue}|"  $lookupFile`
        do
                get_values
                let lookupValuesFound=$lookupValuesFound+1
      process_a_directory
   done
}
#
#  Command Line Parsing
#
export fileCntr=0
export lookupFile=${FP_ENV}/CDG_Lookup.txt
export cdgFileList=$FP_FTP_DOWN/cdg_loaded_files.txt   # list of files already loaded.
#  remove this next line after testing is done
#
# export FP_CDG_CFR=/fpapps/op/qa/ftproot/cdgtest
#
if [ $# -ne 1 ]
then
   usage_msg
fi
while getopts "k:" option
   do
   case  "$option" in
   k) keyValue="$OPTARG"
      ;;
   [?])
      usage_msg
      ;;
   esac
   done
#
#
if [ "$keyValue" = "" ]
then
        exit_func
fi
#
find_and_load_new_files
#
if [ $lookupValuesFound -eq 0 ]
then
        echo "\n---> ERROR: No values found in lookup file. "
        rc=30
else
        echo "\n---> $lookupValuesFound lookup values found"
fi
#
echo "\n---> Total Files processed is $fileCntr \n"
exit_func

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help me in getting the desired output

I wanted to put "|" this sign at starting and at end of every field but its not working with first field like Currently the out put is : abc | abc | abc | xyz | xyz | xyz | But I want the out put in this form: | abc | abc | abc | | xyz | xyz | xyz | plz help me. (2 Replies)
Discussion started by: akash
2 Replies

2. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

3. Shell Programming and Scripting

how to get desired output after redirection

hi i am running script which contains the commmnds and i am redirecting the script output to a file. like ./script 1> result.txt 2>&1 the above redirection is not working for commands when run in background in a script. but the problem here result.txt containg output which is repeated.... (3 Replies)
Discussion started by: raji
3 Replies

4. Shell Programming and Scripting

SED - output not desired

echo '0x3f 0xfa ae 0xeA' | sed '/0x/ y/abcdef/ABCDEF/' output: 0x3F 0xFA AE 0xEA echo '0x3f 0xfa ae 0xeA' | sed -r '/0x{2}/ y/abcdefg/ABCDEFG/' output: 0x3F 0xFA AE 0xEA my expected output: 0x3F 0xFA ae 0xEA What I want to achieve is change all hexadecimals to UPPER case(only those... (6 Replies)
Discussion started by: kevintse
6 Replies

5. Shell Programming and Scripting

need to get the desired output

Below is the my cide which is working fine but I am not getting the output indesired format.there is some problem in alignment.Can someone help me to correct this? if ]; then summary=$( echo -e "Please review the log file of auto coloclean utility.\n"; echo -e... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

6. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

7. Shell Programming and Scripting

Help!! needed to get the desired output

Am in need of your help to get the desired output. nameSECURITY.SERVICES.CONFIG:GETVALUEisPrefetchedNsAccessLast2013-09-13 10:50:13 MESTsAccessTotal1sRunningcHitLastnamePUBLIC.SERVER:INVOKEisPrefetchedNsAccessLast2013-09-17 15:02:05... (5 Replies)
Discussion started by: rocky2013
5 Replies

8. UNIX for Dummies Questions & Answers

Unable to obtain lock on NFS files

Hello , I am creating a controlfile of database in linux and below is the error coming: SQL> CREATE CONTROLFILE REUSE set DATABASE "newdbcln" RESETLOGS NOARCHIVELOG 2 MAXLOGFILES 5 3 MAXLOGMEMBERS 5 MAXDATAFILES 100 4 5 MAXINSTANCES 1 6 MAXLOGHISTORY... (2 Replies)
Discussion started by: admin_db
2 Replies

9. Shell Programming and Scripting

Output not coming as desired.

Hi guys. I have a file containing some hosts and their IPs. host host1 192.168.2.10 host host2 192.168.2.11 host host3 192.168.2.12 I am writing a script where I want to print these values in 1 line. My script looks like RUNTIME_NODE=`cat hosts.properties | grep host` for i in... (7 Replies)
Discussion started by: Junaid Subhani
7 Replies

10. Shell Programming and Scripting

Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!

I have an file which have data in lines as follows ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545 ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26... (3 Replies)
Discussion started by: deepKrish
3 Replies
All times are GMT -4. The time now is 02:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy