Problem in if condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in if condition
# 1  
Old 03-06-2012
Question Problem in if condition

Hi, below is the script in ksh and i am having issues with if condition.
It takes in one argument as input and executes the shell script.
The problem is in if condition in shell script. If input is given as 1 it works out well. But if input is given as 2 or something else the script is failing to go into if condition.
Could some please have a lok and please let me know what is wrong.

below if the if conditions from script belowSmilieits not entering into these given conditions:
------------
if [ "$axisfile" = "v2_pcr2ecm_dly_coverage_$dat".txt ];then
status=`sqlplus -s / @$PCR_HOME/sql/extract/v2_pcr2ecm_dly_coverage.sql $PCR_HOME/data/$axisfile`
status1=$?
fi
--------------


Code:
#!/bin/ksh -x 

. $HOME/.profile 2>/dev/null 
. $PCR_HOME/conf/env.ini 
. $PCR_HOME/bin/log_message.sh 


cd  $PCR_HOME/log 


export input=$1 

dat=`date +"20%y%m%d` 
dat1=`date +%a%t%b%t%d%t%T%t%Z%t%Y` 


if [ $input -eq 1 ] 
then 
rm -f $PCR_HOME/data/v2_pcr2ecm_dly_rds_clients*.txt 
rm $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
axisfile="v2_pcr2ecm_dly_rds_clients_$dat".txt 
axisokfile="v2_pcr2ecm_dly_rds_clients_$dat".ok 

elif [ $input -eq 2 ] 
then 
rm -f $PCR_HOME/data/v2_pcr2ecm_dly_rds_coverage*.txt 
rm $PCR_HOME/log/$pcr2ecm_dly_rds_coverage.log 
axisfile="v2_pcr2ecm_dly_coverage_$dat".txt 
axisokfile="v2_pcr2ecm_dly_coverage_$dat".ok 

elif [ $input -eq 3 ] 
then 
rm -f $PCR_HOME/data/v2_pcr2ecm_dly_rds_products*.txt 
rm $PCR_HOME/log/$pcr2ecm_dly_rds_products.log 
axisfile="v2_pcr2ecm_dly_pcr_products_$dat".txt 
axisokfile="v2_pcr2ecm_dly_pcr_products_$dat".ok 


elif [ $input -eq 4 ] 
then 
rm -f $PCR_HOME/data/v2_pcr2ecm_dly_rds_employees*.txt 
rm $PCR_HOME/log/$pcr2ecm_dly_rds_employees.log 
axisfile="pcr2ecm_dly_rds_employees_$dat".txt 
axisokfile="pcr2ecm_dly_rds_employees_$dat".ok 

fi

started="started_executing_$axisfile" 
ended="ended_executing_$axisfile" 
error="error_during_extract" 
error1="error_during_extraction1" 
norows="norows_extracted" 
start_ftp="started_ftp_the_file" 
end_ftp="ended_ftp_the_file" 

echo "Creating :  $axisfile" 


#export $extract_log=${axisfile%%.*}.log 
#extract_log=/data/eqpcs/pcrusr/pcr/log/pcr2ecm_dly_rds_clients.log 


#echo `date '+%d-%m-%y %H:%M:%S'`  "Extract process started" >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 

sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile 0 $started 


if [ "$axisfile" = "v2_pcr2ecm_dly_rds_clients_$dat".txt ];then 
status=`sqlplus -s / @$PCR_HOME/sql/extract/v2_pcr2ecm_dly_rds_clients.sql $PCR_HOME/data/$axisfile` 
status1=$? 
fi 

if [ "$axisfile" = "v2_pcr2ecm_dly_coverage_$dat".txt ];then 
status=`sqlplus -s / @$PCR_HOME/sql/extract/v2_pcr2ecm_dly_coverage.sql $PCR_HOME/data/$axisfile` 
status1=$? 
fi 

if [ "$axisfile" = "v2_pcr2ecm_dly_rds_products_$dat".txt ];then 
status=`sqlplus -s / @$PCR_HOME/sql/extract/v2_pcr2ecm_dly_pcr_products.sql $PCR_HOME/data/$axisfile` 
status1=$? 
fi 

if [ "$axisfile" = "v2_pcr2ecm_dly_rds_employees_$dat".txt ];then 
status=`sqlplus -s / @$PCR_HOME/sql/extract/pcr2ecm_dly_rds_employees.sql $PCR_HOME/data/$axisfile` 
status1=$? 
fi 



wcl=`wc -l $PCR_HOME/data/$axisfile` 
file_cnt=`echo $wcl | cut -f1 -d " "` 
file_cnt=`expr $file_cnt - 1` 
#echo "File Count : $file_cnt"  >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
hash_value=`cksum $PCR_HOME/data/$axisfile | awk '{print $1}'` 

rm -f $PCR_HOME/log/$axisokfile 
echo $dat1 > $PCR_HOME/log/$axisokfile 
#echo "\nNo. of rows in the generated file  :$file_cnt" >> $PCR_HOME/log/$axisokfile 
#echo "\n CheckSum Value is :$hash_value" >>  $PCR_HOME/log/$axisokfile 
echo "$hash_value" >>  $PCR_HOME/log/$axisokfile 

#echo "status : $status1"  >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
#echo `date '+%d-%m-%y %H:%M:%S'`  "Extract process completed" >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 

 sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile $file_cnt $ended 

if [ $status1 -ne 0 ] 
  then 
     sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile 0 $error 
     #echo `date '+%d-%m-%y %H:%M:%S'` "FATAL - Error in ECM extraction Process \n\n" >> $PCR_HOME/log/

$pcr2ecm_dly_rds_clients.log 
     cat $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log | mailx  -s "Fatal - Error in ECM Extraction process "  

abc@abc.com 
     echo `date '+%d-%m-%y %H:%M:%S'`  "Email Successfully Sent Out1" >>  $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 

     exit 1; 
elif [ $file_cnt -eq 0 ] 
   then 
     sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile 0 $norows 
     #echo "\nNo rows in ECM extract.Please look into that" >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
     cat $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log | mailx  -s "No rows in ECM extract.Please look into that "  

abc@abc.com 
     exit 1; 
elif [ `cat  $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log | grep -i "ERROR" | wc -l` -gt 0 ] 
   then 
   sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile 0 $error1 
    #echo "FATAL - Error in extraction Process Table\n\n" >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
     cat $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log | mailx  -s "Fatal - ECM Extraction process Failed "  

abc@abc.com 
     #echo `date '+%d-%m-%y %H:%M:%S'`  "Email Successfully Sent Ou2t" >> $PCR_HOME/log/$pcr2ecm_dly_rds_clients.log 
     exit 1; 

elif [ "$axisfile" = "v2_pcr2ecm_dly_rds_clients_$dat".txt -o "$axisfile" = "v2_pcr2ecm_dly_coverage_$dat".txt -o 

"$axisfile" = "v2_pcr2ecm_dly_rds_products_$dat".txt -o "$axisfile" = "v2_pcr2ecm_dly_rds_employees_$dat".txt -o 

"$axisfile" = "v2_pcr2ecm_dly_rds_teams_$dat".txt ]; then 

#echo "File copying to ECM server " >> $PCR_HOME/log/$axisokfile 
################################################## 
# csv file is ftped to ECM server 
################################################## 
    
sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile $file_cnt $start_ftp 

#cd $PCR_HOME/data 

#sftp $DA_USER@$DA_SERVER <<END 
#lcd $PCR_HOME/data 
#put $axisfile $DA_DIR/$axisfile 
#lcd $PCR_HOME/log 
#put $axisokfile $DA_DIR/$axisokfile 
#bye 
#END 

sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile $file_cnt $end_ftp 

cd $PCR_HOME/data 

gzip -9 $PCR_HOME/data/$axisfile 

exit 0 

fi 


if [ "$axisfile" = "v2_pcr2ecm_wkly_mainbase_maps_$dat".txt ]; 
then 

sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile $file_cnt $start_ftp 

cd $PCR_HOME/data 

sftp $DAMB_USER@$DAMB_SERVER <<END 
lcd $PCR_HOME/data 
put $axisfile $DAMB_DIR/$axisfile 
lcd $PCR_HOME/log 
put $axisokfile $DAMB_DIR/$axisokfile 
bye 
END 

sqlplus -s / @/data/eqpcs/pcrusr/pcr/sql/extract/extract.sql $axisfile $file_cnt $end_ftp 

cd $PCR_HOME/data 

gzip -9 $PCR_HOME/data/$axisfile 

exit 0 

fi

Smilie

Last edited by abhi_123; 03-06-2012 at 02:38 AM.. Reason: Please use code tags; do not cross post
# 2  
Old 03-06-2012
There is a missing double quotes in dat=`date +"20%y%m%d"` and as a good practice whenever you concatenate variable with strings, cover the variable with curly braces,

like "$axisfile" = "v2_pcr2ecm_dly_coverage_${dat}.txt". This ensures that variables are expanded and concatenated as is.

Last edited by michaelrozar17; 03-06-2012 at 03:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Condition problem

Hi All, Seeking for your assistance on how to condition it correctly. cat file1.txt 290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00 290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00 290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00 1st scenario: if the fourth column contains 888s and 0s it is by... (16 Replies)
Discussion started by: znesotomayor
16 Replies

2. Shell Programming and Scripting

If condition problem

Hi All, I am using below if condition to check whether null is passed as a parameter to the program if or ; then echo "ABC">>$FILE else echo "CDF">>$FILE fi However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies

3. Shell Programming and Scripting

Problem with IF condition .

Hi i am writing a script where i am running , 5 scripts together in 1 script . Now what i want is when these 5 scripts run completely , i should execute some other commands like i have compile the data etc. I have have 5 echo statements at the end of all those scripts . Like echo "1 is done" in... (1 Reply)
Discussion started by: honey26
1 Replies

4. Shell Programming and Scripting

If condition problem

Hi, I need to use if condition for search a file pattern on a particular location. cd $file_Path if || then do this else do that fi Can someone help me with the if part, how i can put those conditions? make sure format should be *.file* and *.file file is a keyword which i... (5 Replies)
Discussion started by: amit.mathur08
5 Replies

5. Shell Programming and Scripting

Problem in if condition

Hi all, I have task to delete two different files from all file system. one is core file & other is old file. i can delete core file but for old file i have to mv in different location. i wrote a script but it is not working. i have a two variables in this script first one is delcnt &... (6 Replies)
Discussion started by: dravi_laxmi
6 Replies

6. Shell Programming and Scripting

Problem in using AND OR condition together

a=rhino b=crocodil c=testsc if && "$c" = testsc ] then echo "Test #5 succeeds." else echo "Test #5 fails." fi i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Discussion started by: gokulraj23
11 Replies

7. Shell Programming and Scripting

problem in if then else condition

Hi , I am trying the following simple script . But it is always giving 1 output. Dont know why #!/bin/sh find . -name "a.log" if ; then echo "1" else echo "0" fi Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies

8. Shell Programming and Scripting

problem in if condition

hi, actully i need the belp for the below. host_list=" Host1 host2 host3 host4 " n=`hostname` i need to put the condition like the below if n is among the host mention in the host_list if then #some stugg else # some other stuff fi (1 Reply)
Discussion started by: mail2sant
1 Replies

9. Shell Programming and Scripting

problem with if condition

hi, :) pls consider the following if statement if //g') ] then ........ else ....... when i execute the script i am getting the following error '(' unexpected I am not able to find the mistake. could anybody tell where i did mistake. cheers RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies

10. Shell Programming and Scripting

If condition problem

Hi Guys, I want to use if conition for my script. Before I used it tried it with some small test scripts. But it was not succeeded. My script and screen output as follows, Script: echo 'Do you think Yes or No (y/n) : ' read ans echo You input anser as $ans ans1=y if ( $ans == $ans1... (5 Replies)
Discussion started by: maheshsri
5 Replies
Login or Register to Ask a Question