1

I am trying to use 'or' condition within 'if' statement in shell script (Bash/Solaris). I am trying below, but it is giving Syntax error.

What mistake I am doing?

if [ grep "$logtime" $blogs | grep "Authentication Failed" ] -o [ grep "$logtime" $slogs | egrep "AAA Authentication Failure|AAA Authorization Failure" ] > dptest 2>&1;then

    set of commands.

fi

Regards, Rahul

1 Answer 1

1

Don't put commands inside [ ... ]; this is used for testing expressions.

if ( grep "$logtime" $blogs | grep "Authentication failed" || grep "$logtime" $slogs | egrep "AAA Authentication Failure|AAA Authorization Failure" ) > dptest 2>&1
then
    # commands
fi

The parentheses in my answer are not part of the syntax of if, they're used to group the commands so that all the output will be redirected to dptest.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.