Swatchdog – Simple Log File Watcher in Real-Time in Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. Rosalind Benoit says:

    I just started using Swatch(dog) today on rhel and am psyched as I was originally going to have to reinvent the wheel here. Can you help me with one thing? I need to tail a specific logfile and watch for a string indicating that there may be stuck threads in my threaded java app.

    Then I’ll execute a script to generate thread dumps if the string is found. All good, but the only problem is, the name of the logfile changes every day, as the current date is appended to the filename. So what I want is to be able to add:

    swatch --config-file=/home/myuser/swatch/td-swatch-config --tail-file=/my/app/path/logs/tomcat/stdout-stderr-********.log --daemon

    to cron and have it always know to tail today’s log, whether it be stdout-stderr-20180801.log or stdout-stderr-20190101.log, etc.

    Can you help me with that? Is there an easy way? One thing I thought of would be to put the swatch command in its own script which uses variables to define the right filename (ex. dateString={date +”%m-%d”//[-]/} tailString= ‘/opt/blackboard/logs/tomcat/stdout-stderr’+$dateString+’.log’) and then run that swatchdog script every day. But then is there more overhead on effectively killing the swatchdog process when it no longer needs to be watching a file that won’t change anymore?

    Advise pretty please : )

    • Aaron Kili says:

      @Rosalind

      “One thing I thought of would be to put the swatch command in its own script which uses variables to define the right filename (ex. dateString={date +”%m-%d”//[-]/} tailString= ‘/opt/blackboard/logs/tomcat/stdout-stderr’+$dateString+’.log’) and then run that swatchdog script every day.”

      This is the possible solution, and you have to deal with the system overhead, because as long as your threaded java app continues to run, then the swatchdog script also needs to continue running to watch stuck threads. The simple idea is continuous monitoring of a file using swatchdog, this definitely causes system overhead.

  2. neo says:

    Isn’t watch -n1 tail /var/log/syslog enough?

    • Ravi Saive says:

      @Neo,

      That’s not enough, because Swatchdog uses regular expression and pattern to monitor particular string in a log file, also it has a feature to highlight those string in bold or color fashion in the output.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.