Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:47:14+00:00 2026-06-18T09:47:14+00:00

I’m writing a node.js function to ssh to a remote machine, and attempt to

  • 0

I’m writing a node.js function to ssh to a remote machine, and attempt to scrape logs for exceptions from a variety of different log files. The important bit of the log file will look something like this:

.... gunk ....



2013-01-29 04:06:39,133 com.blahblah.BaseServlet processRequest Thread-1629  Site-102 Cons-0 Url-http://theurlthat.com/caused/the/problem App-26 yada yada yada

java.lang.NullPointerException
        at com.blahblah.MyClass.hi(MyClass.java:173)
        at com.blahblah.StandardStackTrace.main(StandardStackTrace.java:125)
        at com.blahblah.SoOnAndSo.forth(SoOnAndSo.java:109)
        at java.lang.Thread.run(Thread.java:595)


2013-01-29 04:06:39,133 com.blahblah.BaseServlet defaultThrowableHandler Thread-1629  Site-102 Cons-0 Url-http://theurlthat.com/caused/the/problem App-26 yad yada yada

TechnicalDifficultiesException: TD page delivered by handleThrowable
http://theurlthat.com/caused/the/problem


....more gunk....

I need to find the exception and corresponding date in the log file that meets the following three requirements:

  1. The exception must be the first that precedes this static text:

    TechnicalDifficultiesException: TD page delivered by handleThrowable

  2. The Exception must be directly between two lines that have “BaseServlet.*Site-102”

  3. The exception must be the most recent (last) in the log files that meets the above conditions. The log is rolled over periodically, so it need to be the last in Log, or if that doesn’t exist the last in Log.001, or if that doesn’t exist the last in Log.002, etc.

Since this program has to ssh into one of many potential servers, it’s better to only have to maintain the logic in the node.js program and not on the machines with the logs. Thus, a one-liner in perl/sed/awk/grep/etc would be most ideal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:47:16+00:00Added an answer on June 18, 2026 at 9:47 am

    So your question looks like this, if I understand correctly:

    • The log file has a number of sections seperated by double newline.
    • Each is headed by a line with a date etc..
    • We are only interested in the sections whose headers match /BaseServlet.*?Site-102/.
    • If the body of a section matches /^TechnicalDifficultiesException: TD page delivered by handleThrowable/, we want to select the body of the previously matched section, which we should maybe validate to look like a java exception.
    • We process the whole log file, and return the last exception found this way.

    Fair enough.

    #!/usr/bin/perl
    use strict; use warnings;
    local $/ = ""; # paragraph mode
    my ($prev_sec, $prev_err);
    SECTION:
    while (my $head = <>) {
      my $body = <>;
      defined $body or die "Can't read from empty filehandle.";
      next SECTION unless $head =~ /BaseServlet.*?Site-102/;
      if ($body =~ /^TechnicalDifficultiesException: TD page delivered by handleThrowable/) {
        $prev_err = $prev_sec;
      }
      $prev_sec = $body;
    }
    die "No error found" unless defined $prev_err;
    print $prev_err;
    

    (not really tested that much, but prints out the error from your snippet)

    The code is a bit to long for a one-liner. You could always pipe the source into the perl interpreter, if you wanted.

    perl -ne'BEGIN{$/=""}END{print$prev_err}$b=<>;defined$b or die"empty FH";/BaseServlet.*?Site-102/ or next;$prev_err=$prev_sec if $b=~/^TechnicalDifficultiesException: TD page delivered by handleThrowable/;$prev_sec=$b'
    

    Specify the log file as a command line argument, or pipe the file contents directly into that program. Finding the correct log file isn’t hard. In a snippet of Perl:

    my $log_dir = ...;
    my ($log) = sort glob "$log_dir/LOG*";
    die "no log in $log_dir" unless defined $log;
    

    Update

    If the date should be captured as well, the code would change to

    #!/usr/bin/perl
    use strict; use warnings;
    local $/ = ""; # paragraph mode
    my (@prev, @prev_err);
    SECTION:
    while (my $head = <>) {
      my $body = <>;
      defined $body or die "Can't read from empty filehandle.";
      next SECTION unless $head =~ /BaseServlet.*?Site-102/;
      if ($body =~ /^TechnicalDifficultiesException: TD page delivered by handleThrowable/) {
        @prev_err = @prev;
      }
      @prev = ($head, $body);
    }
    die "No error found" unless @prev_err;
    my ($date) = $prev_err[0] =~ /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d),/;
    print "$date\n\n$prev_err[1]";
    

    And as the one-liner:

    perl -ne'BEGIN{$/=""}END{@perr||die"No error found";($date)=$perr[0]=~/^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d),/;print"$date\n\n$perr[1]"}$b=<>;defined$b or die"empty FH";/BaseServlet.*?Site-102/ or next;@perr=@p if $b=~/^TechnicalDifficultiesException: TD page delivered by handleThrowable/;@p=($_,$b)'
    

    I don’t understand how it could only return the first match; this code should process the whole file. If you could provide a more complete testcase, I could verify that this code works as required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.