sekar sundaram
Honored Contributor

AND, OR with IF and GREP - statements in shell scripting

Hi,
Please suggest about:
1. AND, OR operations inside an IF condition
2. AND, OR operations inside GREP

AND and OR operations give confusions and issues all the times(which braket"(" or "[[" or, ,,etc,...). can you please write how to use them with simple examples.

ISSUE: i have this output in a file(output-file). i would like to run an opcmsg if either rds, crs, mmd or kms is down.

OUTPUT-FILE:
**************
oper@corvette:/home/oper=>omnisv -status
ProcName Status [PID]
===============================
rds : Down
crs : Active [9569]
mmd : Active [9566]
kms : Active [9567]
omnitrig: Active
uiproxy : Active [9571]
===============================
Status: At least one of Data Protector relevant processes/services is not running.
**************

i wrote like this:
RDS=`grep -c rds output-file | grep -c Down`
CRS=`grep -c crs output-file | grep -c Down`
MMD=`grep -c mmd output-file | grep -c Down`
KMS=`grep -c kms output-file | grep -c Down`

if[[ $RDS -eq 1 || $CRS -eq 1 || $MMD -eq 1 || $KMS -eq 1 ]]
then
echo "At least one of Data Protector relevant processes/services is not running."
fi