Hi all,
i have a logfile which is continuously being updated. I have built a script to check for a specific content and if it is found, it sends a string into a file. Here's the current script:
#!/bin/bash
logfile=/opt/jboss-eap-6.3/standalone/log/server.log
tail -fn0 $logfile | \
while read line ; do
echo "$line" | grep -q "SocketTimeoutException invoking http://10.192.1.8:8001: connect timed out"
if [ $? = 0 ]
then
echo "ConnectionTimeout_ESB-OldStack=YES" > /home/nms/Disconnection_oldstack.txt
else
echo "ConnectionTimeout_ESB-OldStack=NO" > /home/nms/Disconnection_oldstack.txt
fi
done
As you can see i am continuously reading from the "server.log" file and while reading each entry, if the "grep" command find the matched string it echoes to file, else it echos to the same file but with a different string (YES or NO).
However i noticed that when the end of the day is reached, i.e @ 23:59, the file "/home/nms/Disconnection_oldstack.txt" stops updating. I noticed that the "server.log" file closes and a new one is reopened at that time, here below:
-rw-r--r--. 1 jboss jboss 29304874 Feb 10 23:59 server.log.2017-02-10.gz
-rw-r--r--. 1 jboss jboss 21277719 Feb 11 23:59 server.log.2017-02-11.gz
-rw-r--r--. 1 jboss jboss 445767175 Feb 12 23:59 server.log.2017-02-12
-rw-r--r--. 1 jboss jboss 782710795 Feb 13 23:59 server.log.2017-02-13
-rw-r--r--. 1 jboss jboss 143127996 Feb 14 09:40 server.log
i tried to add
while [ ! -f $logfile ]; do sleep 5; done
in the beginning of the script so it sleeps if file is does not exist (since i thought that at the time of the file rotation it stops since the file is not found), but the same thing happened.
Am i missing something?
Note: The output redirection to file is necessary in this case so i need to stick to that!
Thanks in advance for your feedback!