Hello pixellany,
Yes, in fact I know about redirecting the results to a file.
The point is, I intended to assign the value to variable because the script will be taking actions depending on the results loaded at that variable.
Let me illustrate the meaning using an example..
Let's assume we have an application running, and it's logging its status on a regular basis.
Let's assume that application logs look like this:
Code:
Oct 17 04:09: Processing Started..
Oct 17 05:09: Still working, Every thing is Alright.
Oct 17 06:09: Still working, Every thing is Alright.
Oct 17 07:09: Oops..!! fatal error found..!!
Oct 17 07:09: Processing Stopped..!!
Oct 17 08:09: Processing Started..
Oct 17 09:09: Still working, Every thing is Alright.
Oct 17 10:09: Still working, Every thing is Alright.
Oct 17 11:09: Done, completed all tasks successfully.
My script is meant to read that log file, and take action according to the value..
So, an example will be like this:
Code:
#!/bin/bash
result=$(tail /var/log/application_log_file -n1 | grep 'successfully')
if [[ $result != '' ]]; then
# Do some action, like halting the machine:
halt -p
exit 0
else
result=$(tail /var/log/application_log_file -n1 | grep 'fatal error found')
if [[ $result != '' ]]; then
# Do some other action, like restarting the application:
application restart
exit 0
fi
fi
Kindly, Give me your opinion if you see or recommend something in such a case..!! :-)
Thanks a lot.