Hi Kris, welcome to LQ!
I'm not 100% sure I understand exactly what you're trying to do, but I do understand that you want to scan the log files for the SUCCESSFUL message.
First, a few tips to get you started:
1) in bash, use ELIF
, not ELSIF
, and either way, these need to be accompanied by an opening IF
and a closing FI
some code here...
if [ something A ]; then
..do something B..
elif [ something else ]; then
..do something C..
2) the tail command (or any command for that matter) will keep control of execution until it is killed, unless you put an ampersand after a command. If you don't use an ampersand, the tail command will start, but the rest of your script will not execute. Example:
shell$ tail -f somefile.txt #this will run forever until killed
shell$ tail -f somefile.txt & # the & will make the command 'fork' into the background, so execution will continue on..
3) tail will not work if the file does not exist yet, so you have to make a choice of some sort: either create the logfiles initially, using the "touch" command (assuming you know what they will be called) or wait until you're sure the logfiles exist, and THEN do a little search to locate all the logfiles and either do a tail on them, or just grep them for the success/failure messages.
4) Unless you need to know immediately whether there's a success/failure message, you don't need to use tail; if you don't need to know the instant a message occurs, just grep the logfiles after the job is done.
5) If you can wait till the process is done, to check the logs, you could do something like:
for filename in /path/to/log01*.txt; do
if [ "$(grep "SUCCESSFUL" $filename)" ]; then
echo "Woohoo! Success!"
echo "Boo!! Failure.."
I hope this helps you get going but if you need more help, just ask away!