D
D
Dmitry Erokhin2015-03-06 13:14:45
bash
Dmitry Erokhin, 2015-03-06 13:14:45

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

4 answer(s)
D
Dmitry Erokhin, 2015-03-16
@erohin_d

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(

S
ShamblerR, 2015-03-06
@ShamblerR

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.

D
Daniel, 2015-03-06
@flameflower74

Can you decipher the date format?

A
Archie Kuznetsov, 2015-03-06
@Wolf4ara

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 question

Ask a Question

731 491 924 answers to any question