I need to the following things to make sure my application server is
Is there a way to include time outs in a while loop ?
The tail command is fast and simple. But if you want more than just following a file (e.g., scrolling and searching), then less may be the command for you. Press Shift-F. This will take you to the end of the file, and continuously display new contents.
$() – the command substitution. ${} – the parameter substitution/variable expansion.
grep is a command line tool that can search for matching text in a file, or in output from other commands. It's included by default in most Linux distributions and is also available for Windows and Mac. To perform a simple search, enter your search string followed by the file you want to search.
#!/bin/bash
tail -f logfile | grep 'certain_word' | read -t 1200 dummy_var
[ $? -eq 0 ] && echo 'ok' || echo 'server not up'
This reads anything written to logfile, searches for certain_word, echos ok if all is good, otherwise after waiting 1200 seconds (20 minutes) it complains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With