#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Thumbs up How to generate a report of the output.


    Hi Guru's,

    I have already written a small perl script to check the status of provided list of url's. Now what i want to do it is i want to generate a small report of the output.

    my script is here:

    my $file='envlist.txt';
    open (INFO,$file);
    my @lines = <INFO>;
    close(INFO);
    foreach my $url (@lines)
    {
    chomp($url);
    print "$url \n";
    require LWP::UserAgent;
    my $ua = LWP::UserAgent->new;
    $ua->agent('Mozilla');
    $login_req = HTTP::Request->new(GET => $url);
    $login_res = $ua->request($login_req);
    $html = $login_res->content;
    if($html =~ /Login/)
    {
    print $stsLine = $stsLine." UP |\n";
    }
    else {
    print $stsLine = $stsLine." DOWN |\n";
    }
    }

    when i run the above script the output will be like this

    UP |
    UP |
    DOWN |
    DOWN |
    UP |
    UP |
    UP |
    UP |
    UP |
    UP |
    UP |

    Now what i wanted is i need the report like this: sample report below

    URL Name Status
    Gmail.com up
    Yahoo.com up
    google.com up

    Can you please help in generating the report like above.

    Regards
    Sailaja.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by sailajapunnam
    Hi Guru's,

    I have already written a small perl script to check the status of provided list of url's. Now what i want to do it is i want to generate a small report of the output.

    my script is here:

    my $file='envlist.txt';
    open (INFO,$file);
    my @lines = <INFO>;
    close(INFO);
    foreach my $url (@lines)
    {
    chomp($url);
    print "$url \n";
    require LWP::UserAgent;
    my $ua = LWP::UserAgent->new;
    $ua->agent('Mozilla');
    $login_req = HTTP::Request->new(GET => $url);
    $login_res = $ua->request($login_req);
    $html = $login_res->content;
    if($html =~ /Login/)
    {
    print $stsLine = $stsLine." UP |\n";
    }
    else {
    print $stsLine = $stsLine." DOWN |\n";
    }
    }

    when i run the above script the output will be like this

    UP |
    UP |
    DOWN |
    DOWN |
    UP |
    UP |
    UP |
    UP |
    UP |
    UP |
    UP |

    Now what i wanted is i need the report like this: sample report below

    URL Name Status
    Gmail.com up
    Yahoo.com up
    google.com up

    Can you please help in generating the report like above.

    Regards
    Sailaja.
    Please can anyown help me in this issue.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,954
    Rep Power
    1225
    There are a number of problems with your code, but the info you need to answer your question is already in the $url var. You simply need to extract the required portion of the url and add that to your print statement.

    Use the URI::Split module to parse the url to extract the portion you need.

    Here's a short example test script.
    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use URI::Split qw/uri_split/;
    use Data::Dumper;
    
    my $url = 'http://forums.devshed.com/newreply.php';
    my @url_parts = uri_split($url);
    
    print Dumper \@url_parts;
    Which outputs:
    Code:
    $VAR1 = [
              'http',
              'forums.devshed.com',
              '/newreply.php',
              undef,
              undef
            ];
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    Hi FishMonger,

    I wanted the report in this format.

    Env name Status
    Google.com up
    yahoo.com up

    Can you please verify it again and also let me know what all other problems in my code.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    Originally Posted by sailajapunnam
    Can you please verify it again and also let me know what all other problems in my code.
    To start with, put the following near the top of your script:

    Perl Code:
    use strict;
    use warnings;


    These will report a certain number of problems that you will need to correct.

    Another problem is that it would be good if you posted your code within code tags, so as to preserve the formatting. This would make your post more readable.

IMN logo majestic logo threadwatch logo seochat tools logo