1

I want to write an if condition in Shell script something like this:

if[ tail -10f logFile | grep -q "RUNNING" ]

So the idea is I have restarted my server and want to perform some action only after the server is started up(RUNNING). So I want to continuously tail the log and check if the server is in RUNNING mode again.

The issue with the above approach is it does not exits even after the server is RUNNING and goes into infinite loop. No code in if or else is printed.

1 Answer 1

1

What about?

while [ $(tail -10 logFile | grep -c RUNNING) -eq 0 ]; do sleep 1; done
Sign up to request clarification or add additional context in comments.

2 Comments

And if 11 lines were logged while you were sleeping?
Instead of [ $(...) -eq 0 ], you could use while ! tail [...] | grep -q RUNNING; do, i.e., use the exit status directly.

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.