Multiple if condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple if condition
# 1  
Old 12-07-2012
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 the first one is getting calulated and second one does not do so ie to check if the file is empty or not

if [[[ $activecountnumbers -ge $Max] && [[ -s windows.log ]] ]]

Please help

---------- Post updated at 04:39 PM ---------- Previous update was at 04:36 PM ----------

I also tried this, but isnt working

if [[[ $activecnt -ge $Max] && [[ `ls -l windows.log | awk '{print $5}'` -eq 0 ]] ]]

Please note that i am working on ksh shelll

Last edited by ajothi; 12-07-2012 at 05:41 PM.. Reason: add points
# 2  
Old 12-07-2012
Code:
if [ condition1 -a condition2 ]; then

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 12-07-2012
Quote:
Originally Posted by ajothi
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 the first one is getting calulated and second one does not do so ie to check if the file is empty or not

if [[[ $activecountnumbers -ge $Max] && [[ -s windows.log ]] ]]

Please help

---------- Post updated at 04:39 PM ---------- Previous update was at 04:36 PM ----------

I also tried this, but isnt working

if [[[ $activecnt -ge $Max] && [[ `ls -l windows.log | awk '{print $5}'` -eq 0 ]] ]]

Please note that i am working on ksh shelll
First you need to determine what the name is of the variable you want to compare. Are you supposed to be comparing $activecountnumbers or $activecnt against $Max? Once you have determined that try something like:
Code:
if [ $activecnt -ge $Max ] && [ -s windows.log ]
then    echo "activecnt is >= Max and windows.log is an existing file with size > 0"
else    echo "activecnt < Max, windows.log does not exist, or windows.log exists but has size 0"
fi

This if statement assumes that your variables are named activecnt and Max; if that isn't the case, change the names to meet your requirements. Note that if activecnt is not a numeric string or Max is not a numeric string, the results are not defined.

The above suggestion will work on any implementation with a test utility that and shell that meet POSIX Standard and Single UNIX Specifcation requirements. There are shortcuts that can be made with ksh and other specific shells that aren't as portable. You can use vgersh99's suggestion on an implementation that conforms to current UNIX branding requirements or on an implementation of the POSIX Standard that supports this obsolescent feature of the X/Open System Interfaces option. I would not use test's -a primary in new code. (Note that the test utility has two major synopsis forms:
Code:
test expression

and
Code:
[ expression ]

Both forms produce equivalent results.)
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 12-09-2012
Thank you both Don Cragun and vgersh99
I used the second one and it worked!!! thanks much Don!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help search multiple condition from a file.

OS: window 7 shell : korn shell I have 2 file , i'm need grep data according File_1 from file 2. File_1 CAL_ENAB_N_4_ $2N12743_29 +12V File_2 NODE CAL_ENAB_N_4_ PINS 21548; PROBES P1465 3651, 46900 tn2700.1 LWT; WIRES (6 Replies)
Discussion started by: kttan
6 Replies

2. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

3. Shell Programming and Scripting

Reading multiple lines with condition

Hi guys, I need to read following lines and put them in same row …. text: Abcd5437_XYA0_B1_WXYZ_BE 99:00:14:42:55:01:d4:22 99:00:14:42:70:01:d4:22 99:00:14:42:55:03:a0:22 99:00:14:42:70:03:a0:22 ... (4 Replies)
Discussion started by: dc@bos
4 Replies

4. UNIX for Dummies Questions & Answers

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... (5 Replies)
Discussion started by: dsfreddie
5 Replies

5. Shell Programming and Scripting

multiple condition matching and doing some predefined work

Hi everybody, I had 10 files in in one folder(/home/sai/) namely sai. 1.gz,2.gz,3.gz ..,10.gz. I want to delete the files which are there home based on the following conditions fliecount in sai folder==10 && grep -cv ".gz"==0 How to check this using awk? Otherwise please... (2 Replies)
Discussion started by: p_sai_ias
2 Replies

6. Shell Programming and Scripting

Multiple condition checking in bash

Hi All, I am trying to check if two variables have value assigned to it. i am doing it like if ] then echo "Please specify either single hostname or host file for the report" usage exit fi But its not working for it.Even i specify values for both variables it dont go... (6 Replies)
Discussion started by: kailash19
6 Replies

7. Shell Programming and Scripting

multiple echo statements in if condition

Hi , I have a peculiar problem. i have an if block like this if ; then echo " todays date is " ${date} >> log_file echo " file count is " $ count >> log_file mv filename1 filename 2 else echo "no files available ">> log_file fi the echo statement "no files available " is not... (2 Replies)
Discussion started by: wizardofoz
2 Replies

8. Shell Programming and Scripting

awk with multiple condition

Hi Guys, I just wanted to print all the lines execpt 1st and 3rd line. For that i wrote a awk command, awk 'NR != 1 || NR != 3 {print $0}' c.out the command is working if i give an equal to instead of not equal to. In the case of not equal to, it gives me the entire file. Can you... (18 Replies)
Discussion started by: mac4rfree
18 Replies

9. 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

10. 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
Login or Register to Ask a Question