LINUX Multiple condition in IF Statement - Pls help


 
Thread Tools Search this Thread
# 1  
LINUX Multiple condition in IF Statement - Pls help

Hi All,

I am trying to put multiple conditions in an IF Statement (using $$). the Linux script somehow doesnt like it. The logic I am trying to implement is as follows,

1. I will first search for DateFile.txt
2. If it exists & there is a P_BUS_DATE value in it, then assign the date value to BUS_DATE else assign Current day value to it.

Pls find the part of the script i am trying the above logic,

---------------------------------------------------------------
Code:
file_exist=`ls $COMMON_TMP/DateFile.txt`
Dyn_file_chk=$?
if [[ $Dyn_file_chk == 0]] && [[`cat filedir/DateFile.txt | grep -q 'P_BUS_DATE' == 0`]];
then 
  export BUS_DATE=`cat filedir/DateFile.txt | grep 'P_BUS_DATE' | cut -d"=" -f2`
else 
  export BUS_DATE=`date "+%Y%m%d"`
fi

---------------------------------------------------------------
Can you pls tell me what I am doing wrong here.
Thanks for your help

Freddie

Moderator's Comments:
Mod Comment Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-05-2012 at 11:05 PM..
# 2  
Code:
grep -iqw P_BUS_DATE $COMMON_TMP/DateFile.txt 2>/dev/null
if [ $? -eq 0 ];then
    BUS_DATE=`grep -i P_BUS_DATE | cut -d  = -f 2`
else
    BUS_DATE= `date "+%Y%m%d"`
fi

# 3  
At any rate you need to leave space around the square brackets:
Code:
if [[ $Dyn_file_chk == 0 ]]
                        ^
                        |

# 4  
LINUX Multiple condition in IF Statement - Pls help

Thank You Shailesh for your reply.

I am curious abt the below command grep -iqw.
Will it help me to check whether the Datefile is available as well as the particular string is present in it ? Can you Pls clarify. ( My requirement is to search for the DateFile as well as the existance of the string P_BUS_DT in it)

Thanks much
Freddie
# 5  
well if the file doesn't exist return code of grep will non 0 and so it will if file exists but your pattern doesn't exist in file. Meaning the return code of grep -iqw P_BUS_DATE $COMMON_TMP/DateFile.txt 2>/dev/null will be 0 only if file exist and pattern is found in file.
This User Gave Thanks to 47shailesh For This Post:
# 6  
LINUX Multiple condition in IF Statement - Pls help

I got it Shailesh. Looks like it is workingSmilie

Do you know whether the 2>/dev/null directory will be the same in PROD as well ?

Thanks for your help
Freddie
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #738
Difficulty: Medium
RadioShack introduced a 50 MB external hard disk for the TRS-80 Model III/4 in 1983.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

If statement with unmatched condition

Hi Gurus, I'm facing some issues with multiple conditions in my if statement. if (!($InputLine=~/^Date/)) && (!($fields eq "VEN")) { Above is the line troughing some syntax errors. I am trying to avoid the below creteria lines to process in my logic. Records starting with... (4 Replies)
Discussion started by: hi.villinda
4 Replies

3. Shell Programming and Scripting

Two condition in if statement

Hi, I need to put two condition in if statement, but it is not working. Please suggest. if ---------- Post updated at 07:05 AM ---------- Previous update was at 06:55 AM ---------- Also when i put below command in script it is not running, but manually it is running ... (4 Replies)
Discussion started by: learnbash
4 Replies

4. Shell Programming and Scripting

If condition and for loop within sed statement

Hi, I tried to go through a lot of online material but could not find concrete solution. My issues is like this : I've got a input file like this : <a> <startDate>19700101000000</startDate> <endDate>20300101000000</endDate> </a> ... (12 Replies)
Discussion started by: Shaishav Shah
12 Replies

5. Shell Programming and Scripting

Multiple if condition

Hi, I wanted to satisfy two requirements to proceed to do a task One of them is to calculate between two metrics and the other to check one of the file not empty if the condition matches the above two, it should proceed with the task below is the snippet of it, however when i run the script... (3 Replies)
Discussion started by: ajothi
3 Replies

6. Shell Programming and Scripting

An issue with condition statement in shell script

Hello forum members. please go through the below mentioned issue and let me know the right solution. I have to write a script which runs another script .the executable script take input parmeters.so iam writing the the script below . Sample Code:Begins #! /bin/ksh echo " enter... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

7. Shell Programming and Scripting

Condition statement in perl

#!/usr/bin/perl $output1 = "/home/log.txt" $output2 = "/home/grep.txt" #Statement1 creates an output file called log.txt. #Statement2 greps a line from log.txt and store the result in grep.txt I want to create a condition where if the file grep.txt is empty repeat process. Thanks. (1 Reply)
Discussion started by: sureshcisco
1 Replies

8. Shell Programming and Scripting

multiple condition in if

All, My environment is Red Hat Enterprise Linux 5. I am using the following condition -- if -0 ] above command is not working. It is telling that -a unexpected. Please help me (10 Replies)
Discussion started by: user7509
10 Replies

9. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies

10. Linux

linux .....pls help

hi...anyone pls hepl... i just wanna know some basics of linux like HOW MYSQL WORKS WITH LINUX, WHAT RELAVANCE OF MYSQL WITH LINUX WHAT IS THR ROLE ON MYSQL IN LINUX..AND ONE HAVING ANY IDEA OF MYSQL RELATED WITH LINUX..PLS ANSWER AND REPLY ON sharmapriyanka75@gmail.com thanks (1 Reply)
Discussion started by: priyankas
1 Replies

Featured Tech Videos