Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Need some guidance

Monitor a application log file(log rotation is daily)using tail-f, if exception in log file need to send alert using script.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's hard to build a log monitor with just tail -f. tail does have a +c option to read from a particular position, but it would be tricky to build good code around it.

What you need is this:

  • a read control file that stores the last byte position read from the log file
  • a script that uses the read control file to do incremental reads (using seek) and does pattern matching and notification based on the lines read, and updates the read control file
  • the inode number could be used for naming the read control file so that the incremental logic continues to work even if the log file is renamed or moved

The above script could either run as a daemon or execute periodically as a cron job. I would strongly suggest using Perl, Ruby, Python, or even Java/C/C++ for this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...