Answer the question
In order to leave comments, you need to log in
Loop in bash to check file for string and output message?
You need a script to constantly get into the last log file (there are several logs in the folder, logs are generated by date and time in a format like: 03-06_22-57-25_Ser.log ) check the contents for the presence of a line containing "Server initialization completed" , and when such a line appears, issue the message "Hi".
Answer the question
In order to leave comments, you need to log in
I ended up doing this:
time=`date +%m-%d`
i=`grep Initializing /opt/ruby_projects/VS/line1/rvec/conf/.netbeans-config/var/log/$time*.log | grep server`
while [ -z "$i" ]
do
i=`grep Initializing /opt/ruby_projects/VS/line1/rvec/conf/.netbeans-config/var/log/$time*.log | grep server`
done
echo "Server line01 is running"
Although the problem that this is not the last log remains(
1. Is the log big?
2. tail + grep + if
3. at least have a conscience example of a log, a required line, here telepathy is really bad.
I would do it through syslog + monit (or my "dog", for example, or incron).
source - log file
filter - search string
destination - any file
operation logic:
syslog filters messages and saves them to a file, "dog" or monit or incron perform an action when the file is changed
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question