Function not found error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Function not found error
# 1  
Old 05-11-2015
Linux Function not found error

Hi All,

I have written one shell script where I should call a function by passing variables to the actual function based on some condition.

Each time I run the script I am getting the below error

Code:
dsadm@bunyipd: /var/datastage/FRPDEVL/work/script> sh MClub_Validations.sh
Iteration: 1
MClub_Validations.sh[38]: fn_MClub_Validation:  not found.
Iteration: 2
MClub_Validations.sh[45]: fn_MClub_Validation:  not found.
Iteration: 3
MClub_Validations.sh[52]: fn_MClub_Validation:  not found.
Iteration: 4
MClub_Validations.sh[59]: fn_MClub_Validation:  not found.
Iteration: 5
Successfully completed all Iterations

Below is the code inside the shell script,

Code:
#!/usr/bin/sh
#This loop is to call each case block automatically which will perform validations against each file
for i in 1 2 3 4 5;do
	iteration=$i
	echo "Iteration: "$iteration
	value=$iteration
	case $value in
#If Iteration value=1, then perform validation for MClubAnn_*.txt file
	1)
			dir_loc_1=/var/datastage/FRPDEVL/work/source/landing/dsmcbann
			f_name_1=MClubAnn_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_1 $f_name_1
	;;
#If Iteration value=2, then perform validation for MClubQLD_*.txt file
	2)
			dir_loc_2=/var/datastage/FRPDEVL/work/source/landing/dsmcbqld
			f_name_2=MClubQLD_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_2 $f_name_2
	;;
#If Iteration value=3, then perform validation for MClubNSW_*.txt file
	3)
			dir_loc_3=/var/datastage/FRPDEVL/work/source/landing/dsmcbnsw
			f_name_3=MClubNSW_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_3 $f_name_3
	;;
#If Iteration value=4, then perform validation for MClubWA_*.txt file
	4)
			dir_loc_4=/var/datastage/FRPDEVL/work/source/landing/dsmcbwa
			f_name_4=MClubWA_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_4 $f_name_4
	;;
#End of case block
	esac
#As there are only 4 files after 4 loops once the iteration value is 5, exit the job with normal status.
		if [[ $iteration -eq 5 ]]
		then echo "Successfully completed all Iterations"
		exit 0
		fi
#End of main for loop
done

#Function start to perform validation against each file
fn_MClub_Validation()
{
	cd $1
	for fname in $2;do
#Check for files existence in the corresponding directory and perform validation
		if [ -f "$fname" ]
		then
			echo "Expected file(s) found, Performing Validations for file: "$fname
			filename=`basename $fname`
			fdate=`echo $filename|tr -dc '[:digit:]'`
			echo $filename","$fdate
#Validation: Check the header and data record at which line they are ending and starting respectively.
			echo "------------------------------------------------------------------------------------"
			echo "Checking header and data record Validation for File: $filename"
			echo "------------------------------------------------------------------------------------"  
			count=0
			while read line
			do
				count=`expr $count + 1`  
					if [[ $count -eq 6 && $line == "" ]] || [[ $count -eq 6 && [[ $line == "Initials" || $line == "DATE" || $line == "Box No" ]] ]]
					then echo "The data record is not found at Line No: "$count", Please check the file."
					exit 16
					elif [[ $count -eq 7 && $line == "" ]] || [[ $count -eq 7 && $line == "Listing	No" ]]
					then echo "The data record is not found at Line No: "$count", Please check the file."
					exit 16
					fi
			done < $filename
			echo "The file is as expected"
			echo "------------------------------------------------------------------------------------"
			echo "Header and Data Record Validation check for File: $filename completed"
			echo "------------------------------------------------------------------------------------"
		else
			echo "Expected files not found, Hence not performing any validations"
		fi  
	done
}
#Function end

Please help me what is wrong in my function call, Is it a right way to call a function. Please do help me

With Regards,
TPK

Last edited by tpk; 05-11-2015 at 09:28 AM.. Reason: Corrected with proper comments
# 2  
Old 05-11-2015
The function needs to be defined, before you call it the first time. So put it above the for-loop.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Command not found, but using function in bash

In the bash below, if the answer is "y" then goto function remove. If the answer is "n" then goto the id variable line (where the date is inputted). However, I am getting command remove not found, but remove is a function not an command. I must have the syntax incorrect? Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Bash script fails with "function: not found" error

Hello everyone, I am having problems figuring this out. This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt" When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found component-list.sh:... (4 Replies)
Discussion started by: joemb
4 Replies

4. Shell Programming and Scripting

sh: gzip: not found ERROR

I am creating a script to run the SysInfo tool under HPUX servers, this is my script! #!/usr/bin/ksh # # Date: February 29th 2011 # #Definicion de variables PATH_TMP=/home/eponcede > HPUX_SysInfo.log for host in `cat $PATH_TMP/servers/host_hp2_test` do echo... (2 Replies)
Discussion started by: eponcedeleonc
2 Replies

5. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

6. Shell Programming and Scripting

function: not found error on solaris

shell script in very simple, #!/bin/sh function msgs { echo 'this' } msgs It works on linux, apple, but can not run on solaris. On solaris, when I enter "./t.sh", it gave me following error, ./t.sh: function: not found this ./t.sh: msgs: not found What's wrong with... (3 Replies)
Discussion started by: microstarwwx
3 Replies

7. Shell Programming and Scripting

procedure/function not found in .ksh

Hi all , I am getting an error "job_procfile not found" while excecuting a .ksh script. The script is used to create control-m ( scheduler ) jobs dynamically by reading parameter files ( flat filescomma seperated ) job_procfile is a function within the .ksh script The script is something... (8 Replies)
Discussion started by: rajesh_ramaoz
8 Replies

8. Shell Programming and Scripting

Error in functions : file2: function: not found

Hi I had written the small script for calling a function. bash-2.03$ more file2 function sai { echo " this is an example" } echo "This is main program" echo "calling the function" sai() when executing the above script. I am getting error. bash-2.03$ sh file2 file2: function:... (2 Replies)
Discussion started by: padarthy
2 Replies

9. Shell Programming and Scripting

not found error

Hi I have to move data to a file based on the valuies of first three characters in a file I am using the following script FIN=$LOC/TEST.TXT FEEDFILE=$LOC/TUE_GROSSJE.TXT #Read the file while read FDROW do FEEDROW=$FDROW; DTYPE=`echo $FEEDROW |cut -c 1-3` if ; then $FEEDROW... (4 Replies)
Discussion started by: gander_ss
4 Replies

10. Shell Programming and Scripting

Installer script -- function not found error

I am writing an installation script on AIX. This involves typical checks of some pre requisites like java, oracle, some version checks, disk space etc. It is a long script. I am facing a strange problem. There are a no of functions used in the script. What I see is that the installer complains of... (1 Reply)
Discussion started by: asutoshch
1 Replies
Login or Register to Ask a Question