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

if [ condition1 -a condition2 ]; then
1 Like

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:

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:

test expression

and

[ expression ]

Both forms produce equivalent results.)

1 Like

Thank you both Don Cragun and vgersh99
I used the second one and it worked!!! thanks much Don!!