LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-25-2011, 10:14 AM   #1
smritisingh03
Member
 
Registered: Nov 2010
Posts: 43

Rep: Reputation: 0
Exclamation script has 5 functions but exits only after 2nd function


Hi

I am posting my script.I know its too big but please help!!!!!

Quote:
logcountfunction()

{
awk ' {

# when executing the script pass the logfile as parameter on the command prompt with the name of the file

#export file_name= "&1"

if (index ( $0, ". . exporting table") >0 || index ($0, ". . exporting partition") >0)
#searching for the pattern in string

{


if ($4 != "partition"){
#$4 is either table or a partition

i=$6;
#$6 is the number of rows stored in variable i here

if (table_flag ==0 && table_name ==temp_table_name){
# checking the flag

printf table_name > "logcountOP";
printf "-" > "logcountOP";
print j > "logcountOP";
}

table_name = $5;
#$5 has the name of the table from which the rows have been imported

temp_table_name = table_name;

table_flag =1;
#setting the flag to 1

}




if ($4 == "partition") {

i=i+$6;
#summing up the rows in partitioned tables

printf("value of i in first: %d\n",i);
j=i;
table_flag=0;
#setting flag to 0

}
if (table_flag !=0 && $6 !=""){

printf table_name >> "logcountOP";
printf "-" >> "logcountOP";
print i >> "logcountOP";

}



}
} ' < $1
}

echo -------------------------------------------------------------



#!/bin/ksh

DBcounttry_finalnofunc()

{

cat logcountOP | while read LINE

TBLName=`echo $LINE|cut -d "-" -f1`

do

if [ $LINE != "" ]

then


printf "${TBLName}-" $TBLName


return_count=$(sqlplus -s a/a@abs5 <<EOF

set heading off feedback off pagesize 0 linesize 30000 trimout on;
whenever sqlerror exit 1;
whenever oserror exit 1;

select count (*) from ${TBLName};
exit 0;
EOF)

if [ $return_count -ge 0 ]
then
print "${TBLName}- ${return_count}" >> DBcountOP400
else
echo "$TBLName- is missing" >> DBcountOP400
fi

else
exit
#break
fi



done > DBcountOP3

}


echo -------------------------------------------------------------------------



#!/bin/ksh

comparingloganddbOP()

{


#!/bin/sh

comm -3 logcountOP DBcountOP400 >c.txt

#shows diff


comm -1 logcountOP DBcountOP400 >d.txt

#shows common

}


echo -----------------------------------------------------------------------------


#!/bin/ksh


formattingscript()

{

sed '1,2d' c.txt > newc.txt

awk 'BEGIN{RS="\n\n"} {printf("%s %s\n", $1, $2)}' newc.txt > newcOP.txt

awk 'BEGIN {x = 0}
{
if (x<2) {
printf("%s ",$0)
x=x+1
}
if (x==2) {
printf("\n")
x = 0
}
}' newcOP.txt > newcOP2.txt


}

echo ----------------------------------------------------------------------------------



#!/bin/ksh

finalstatusOP()

{
export file="newcOP2.txt"

while read FILE_LINE ; do

LINE1="$(echo $FILE_LINE | cut -d '-' -f1)"
tablename1="$(echo $LINE1 | cut -d ' ' -f1)"

#echo tablename1 is $tablename1

count1="$(echo $FILE_LINE | cut -d ' ' -f2)"

#echo count1 is $count1

LINE2="$(echo $FILE_LINE | cut -d ' ' -f3)"
tablename2="$(echo $LINE2 | cut -d '-' -f1)"
count2="$(echo $LINE2 | cut -d '-' -f2)"

#echo tablename2 is $tablename2

#echo count2 is $count2

if [ $count1 = "is" ]

then

#echo missing

echo status for $tablename1- does not exist in DB >> statusOP

elif [ $count1 -eq $count2 ]

then

#echo match

echo status for $tablename2 $count2 $count1- match >> statusOP

elif [ $count1 -ne $count2 ]

then

#echo mismatch

echo status for $tablename2 $count2 $count1- mismatch >> statusOP


fi

done < $file

}



##############################MAIN SCRIPT STARTS HERE


#!/bin/ksh

echo "please exit and execute the script again alongwith the logfile name"

. ./logcount

logcountfunction "$1"

. ./DBcounttry_finalnofunc

DBcounttry_finalnofunc

. ./comparingloganddbOP

comparingloganddbOP

. ./formattingscript

formattingscript

. ./finalstatusOP

finalstatusOP

now, the first funtion is taking a logfile as input.The sample is given below:

Quote:
. . exporting table MTM_X79COUNTRY1_X79TZONE0 0 rows exported
. . exporting table MTM_X79LOCATION1_X79SERVICE3 0 rows exported
. . exporting table MTM_X79TELCOM_TR1_X79MO_INST2 0 rows exported
. . exporting table MTM_X79TELCOM_TR2_X79MO_INST1 0 rows exported
. . exporting table MTM_X_MDU_CONTRACT5_X_MDUCLU2 0 rows exported
. . exporting table OMSE1_XML_DISTRIB 0 rows exported
. . exporting table SEC1_LOG
. . exporting partition PR001_P1 0 rows exported
. . exporting partition PR002_P2 0 rows exported
. . exporting partition PR003_P3 0 rows exported
. . exporting partition PR004_P4 0 rows exported
. . exporting partition PR005_P5 0 rows exported
the second function is taking the output file of first function as input,i.e,logcountOP which looks like:

Quote:
ACCOUNT_MISSING_FRM_RCIS_LINK-4
ADP_COMMENT-2311
ADP_CONFIG-11
ADP_FIELD-36323
ADP_HEADER-1
ADP_INDEX-579
ADP_JOIN-14570
ADP_LANGUAGE-2
ADP_NATIVE_SQL-228
ADP_OBJECT-2405
ADP_OBJECT_NEW-2010
ADP_RELATION-4974
ADP_TBL_OID-838
ADP_TBL_OID_UNUSED-0
ADP_UPGRADE_OPS-0

the output of second function looks like:-

Quote:
ACCOUNT_MISSING_FRM_RCIS_LINK- is missing
ADP_COMMENT- 2384
ADP_CONFIG- 11
ADP_FIELD- 36333
ADP_HEADER- 1
ADP_INDEX- 609
ADP_JOIN- 14572
ADP_LANGUAGE- 2
ADP_NATIVE_SQL- 228
ADP_OBJECT- 2405
ADP_OBJECT_NEW- is missing
ADP_RELATION- 4974
ADP_TBL_OID- 839
ADP_TBL_OID_UNUSED- 0
ADP_UPGRADE_OPS- 0
ADP_VIEW_FIELD- 43791

my problem is that when i execute this script only the first two functions are being called.once the DBcounttry_finalnofunc() is done ,the script exits.The rest of the functions are not being called.Please point out where am I goin wrong!!!!

Last edited by smritisingh03; 01-25-2011 at 10:24 AM.
 
Old 01-25-2011, 10:37 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well the second function has an 'else exit option'. My guess would be it is tripping this and exiting.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"exit" in bash .bashrc procedure/shell function exits xterm anonguy9 Linux - Newbie 11 07-13-2011 03:54 PM
Rc.Local Errorlevel Exits Script Cotun Programming 5 03-28-2010 12:54 PM
script exits tostay2003 Programming 4 12-26-2007 08:13 AM
end of file function never exits : C programming exvor Programming 6 10-05-2006 11:35 AM
Flagging exits in Bash Script dtheorem Programming 5 11-08-2003 10:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration