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

  • Home
  • SEARCH
  • 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 909147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:49:47+00:00 2026-05-15T16:49:47+00:00

So far, I have some working code that goes into a list of servers

  • 0

So far, I have some working code that goes into a list of servers and does some regex to grab data from a log file. What I want to do is to pring out a status of “NOTHING TO REPORT FOR THIS SERVER” if there is NO data to capture from the regex on a particular server.

Right now, it goes through each server and if data matches the regex, it will print out.
I added an else statement to print out the above statement to handle this, but now its printing it out for every instance it doesn’t match.

Here is a copy of the output as it works now BEFORE I added the change:

========================================================================
REPORTING SUMMARY for BACKUP SERVER : hostname1
========================================================================
REPORTING SUMMARY for BACKUP SERVER : hostname2
Mon Jul 05 00:30:02 2010: hostname2:backup:INFO: backup-date=20100705003002
Mon Jul 05 00:30:02 2010: hostname2:backup:INFO: host=hostname2
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-size=49.75 GB
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-time=00:25:23
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-status=Backup succeeded
========================================================================

Here is a copy of the output now, AFTER I added the “NOTHING TO REPORT FOR THIS DATE”: (within the while loop). Basically, its printing out this statement everytime it doesn’t match. I really just want it to give me one statement.

========================================================================
REPORTING SUMMARY for BACKUP SERVER : hostname1
NOTHING TO REPORT FOR THIS DATE... 
NOTHING TO REPORT FOR THIS DATE... 
NOTHING TO REPORT FOR THIS DATE... 
...
...
========================================================================
NOTHING TO REPORT FOR THIS DATE... 
Mon Jul 05 00:30:02 2010: hostname2:backup:INFO: backup-date=20100705003002
Mon Jul 05 00:30:02 2010: hostname2:backup:INFO: host=hostname2 
NOTHING TO REPORT FOR THIS DATE... 
NOTHING TO REPORT FOR THIS DATE...
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-size=49.75 GB
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-time=00:25:23
Mon Jul 05 00:55:25 2010: hostname2:backup:INFO: backup-status=Backup succeeded

Here is the code:

# Usage: ./test.pl Ju1 05 2010 <logfilepath> hostname1 hostname2 hostname3
use strict;
use warnings;
my($mon,$day,$year,$file) = @ARGV;
splice(@ARGV, 0, 4, ());            
foreach my $server ( @ARGV ) {      
    print "========================================================================\n";
    print "REPORTING SUMMARY for BACKUP SERVER : $server\n";
    open(my $fh,"ssh $server cat $file |") or die "can't open log $server:$file: $!\n";
    while (my $line = <$fh>) {
        if ($line =~ m/.* $mon $day \d{2}:\d{2}:\d{2} $year:.*(host=|ERROR:|backup-date=|backup-size=|backup-time=|backup-status)/) {
            print $line;
            # adding else statement here
            } else {
            print "NOTHING TO REPORT FOR THIS DATE... \n";
        }
    }
    close($fh);
}
  • 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-05-15T16:49:47+00:00Added an answer on May 15, 2026 at 4:49 pm
    1. Set a boolean to false.
    2. Inside the while loop, if the regex matches, set the boolean to true.
    3. Outside the while loop, if the boolean is still false, print NOTHING TO REPORT.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code that makes use of an open source library to
So far I have encountered adjacency list, nested sets and nested intervals as models
So far i have got the code below which works lovely when trying an
I have thus far built an Editor and a Viewer that both work on
I have an application that has several objects (about 50 so far, but growing).
According to what I have found so far, I can use the following code:
sorry for the vague title. I'm extracting some data from a table with the
I have some radio buttons that are created dynamically with javascript. I need to
I'm working on key handling in Javascript. I have done some research and I'd
I have a regular expression to match a persons name. So far I have

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.