Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Sherlock v0.1

by bpoag (Monk)
on Apr 06, 2009 at 16:34 UTC ( #755780=sourcecode: print w/ replies, xml ) Need Help??

Category: NetBackup
Author/Contact Info Bowie J. Poag (bpoag_at-comast.net)
Description: Sherlock will determine if a given host is known or unknown to a NetBackup master server, regardless of platform type. It's presented here in its unmodified form (we differentiate primary and backup network interfaces by the inclusion of a b_ prefix on the hostname) for the sake of demonstration. Sherlock is known to smoke a pipe made of ivory, and is often condescending while addressing others, including his faithful sidekick, Watson. This predisposes him to developing mouth cancer and a bad reputation. There is a possibility that Watson may know judo, and as such, may use the momentum of an attacker's body to his advantage in executing one or more stunning throw techniques. Executing this code will cause a giant pair of scissors to appear in the skies at above rural England, disappearing after a few moments. No need to be alarmed.

##
## Sherlock v0.1 written 040409:1650 by BJP
##
## Sherlock, given a hostname, can determine if that host is known to 
+netbackup.
##
## Usage:  sherlock.pl <hostname>
##


if ($#ARGV<0)
{
        print "\n\nUsage:  sherlock.pl <hostname>\n";
        print "Example: sherlock.pl cistest\n\n";
        exit();
}

print "\nSherlock: Starting up..\n";

if ($ARGV[0]=~/^b_/)
{
        print "Sherlock: Stripping off the \"b_\" prefix temporarily..
+\n";
        $ARGV[0]=$';
}
print "Sherlock: Checking to see if NetBackup knows about $ARGV[0]..\n
+";

@results=`/usr/openv/netbackup/bin/bpclntcmd -pn -hn $ARGV[0] 2>&1 `; 
+## For some reason, this command will dump ordinary status informatio
+n to stderr versus stdout, hence the gag suffix on the command.


foreach $item (@results)
{
        chomp ($item);

        if ($item=~/TRY_AGAIN/)
        {
                print "Sherlock: Bad news. NetBackup does not recogniz
+e $ARGV[0] as a valid peer name under its care.\n";
                print "Sherlock: Test results: FAIL\n";
                print "Sherlock: Exiting..\n\n";
                exit();
        }

        if ($item=~/0x/)
        {
                print "Sherlock: Good news! NetBackup recognizes $ARGV
+[0] as a valid client and peer name.\n";
                print "Sherlock: Details: $item\n";

                $clientName=$ARGV[0];

                @history=`/usr/openv/netbackup/bin/bpclimagelist -t AN
+Y -client $clientName`;

                if (@history == NULL)
                {
                        print "Sherlock: A check of the backup logs fo
+r this client shows nothing so far.. Still searching..\n";
                        print "Sherlock: This time, let's try again us
+ing a \"b_\" prefix on the hostname and see what happens..\n";
                }
                else
                {   
                        dumpHistory();
                }
                 
                $clientName="b_"."$ARGV[0]";

                @history=`/usr/openv/netbackup/bin/bpclimagelist -t AN
+Y -client $clientName`;
                if (@history == NULL)
                {
                        print "Sherlock: I'm still not seeing anything
+ for this host. Hmmm.. Maybe it's a Wintel box? Lets try that..\n";
                }
                else
                {
                        dumpHistory();
                }
       
                $clientName=$ARGV[0];
       
                @history=`/usr/openv/netbackup/bin/bpclimagelist -t AN
+Y -client $clientName -ct 5`;
       
                if (@history == NULL)
                {
                        print "Sherlock: No luck.. I'm not seeing anyt
+hing on it. Trying again, assuming it's a Wintel box AND \"b_\" prefi
+xed..\n";
                }
                else
                {
                        dumpHistory();
                }
       
                $clientName="b_"."$ARGV[0]";
       
                @history=`/usr/openv/netbackup/bin/bpclimagelist -t AN
+Y -client $clientName -ct 5`;
       
                if (@history == NULL)
                {
                        print "Sherlock: Still no luck. This box needs
+ to be checked manually.\n";
                        print "Sherlock: Test results: FAIL\n";
                        print "Sherlock: Exiting..\n\n";
                }
                else
                {
                        dumpHistory();
                }
        }
}      
       
sub dumpHistory()
{
        print "Sherlock: Ahhh, there we go. Results! This host appears
+ to have a backup history..\n";
        foreach $item (@history)
        {
                chomp($item);
                print "Sherlock: $item\n";
        }
       
       
        print "Sherlock: Test results: PASSED\n";
        print "Sherlock: Exiting..\n\n";
        exit();
}      

Comment on Sherlock v0.1
Download Code
Re: Sherlock v0.1
by jwkrahn (Monsignor) on Apr 06, 2009 at 19:07 UTC

    When I compile that with warnings and strict enabled I get these messages:

    main::dumpHistory() called too early to check prototype at 755780.pl.t +dy line 87. main::dumpHistory() called too early to check prototype at 755780.pl.t +dy line 74. main::dumpHistory() called too early to check prototype at 755780.pl.t +dy line 63. main::dumpHistory() called too early to check prototype at 755780.pl.t +dy line 53. Global symbol "@results" requires explicit package name at 755780.pl.t +dy line 27. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 30. Global symbol "@results" requires explicit package name at 755780.pl.t +dy line 30. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 31. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 33. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 40. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 42. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 44. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 46. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 46. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 48. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 56. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 58. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 58. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 59. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 66. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 68. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 68. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 70. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 77. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 79. Global symbol "$clientName" requires explicit package name at 755780.p +l.tdy line 79. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 81. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 94. Global symbol "@history" requires explicit package name at 755780.pl.t +dy line 94. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 95. Global symbol "$item" requires explicit package name at 755780.pl.tdy +line 96. Bareword "NULL" not allowed while "strict subs" in use at 755780.pl.td +y line 48. Bareword "NULL" not allowed while "strict subs" in use at 755780.pl.td +y line 59. Bareword "NULL" not allowed while "strict subs" in use at 755780.pl.td +y line 70. Bareword "NULL" not allowed while "strict subs" in use at 755780.pl.td +y line 81.

    Perhaps it would work better like this:

    use warnings; use strict; ## ## Sherlock v0.1 written 040409:1650 by BJP ## ## Sherlock, given a hostname, can determine if that host is known to +netbackup. ## ## Usage: sherlock.pl <hostname> ## if ( @ARGV != 1) { print "\n\nUsage: sherlock.pl <hostname>\n"; print "Example: sherlock.pl cistest\n\n"; exit 1; } print "\nSherlock: Starting up..\n"; if ( $ARGV[ 0 ] =~ s/^b_// ) { print "Sherlock: Stripping off the \"b_\" prefix temporarily..\n"; } print "Sherlock: Checking to see if NetBackup knows about $ARGV[0]..\n +"; my @results = `/usr/openv/netbackup/bin/bpclntcmd -pn -hn $ARGV[0] 2>& +1 `; ## For some reason, this command will dump ordinary status in +formation to stderr versus stdout, hence the gag suffix on the comman +d. for my $item ( @results ) { chomp $item; if ( $item =~ /TRY_AGAIN/ ) { print "Sherlock: Bad news. NetBackup does not recognize $ARGV[ +0] as a valid peer name under its care.\n"; print "Sherlock: Test results: FAIL\n"; print "Sherlock: Exiting..\n\n"; exit 2; } next if $item !~ /0x/; print "Sherlock: Good news! NetBackup recognizes $ARGV[0] as a valid + client and peer name.\n", "Sherlock: Details: $item\n"; my $clientName = $ARGV[ 0 ]; my @history = `/usr/openv/netbackup/bin/bpclimagelist -t ANY -clie +nt $clientName`; dumpHistory( @history ) if @history; print "Sherlock: A check of the backup logs for this client shows no +thing so far.. Still searching..\n", "Sherlock: This time, let's try again using a \"b_\" prefix on + the hostname and see what happens..\n"; $clientName = "b_$ARGV[0]"; @history = `/usr/openv/netbackup/bin/bpclimagelist -t ANY -client +$clientName`; dumpHistory( @history ) if @history; print "Sherlock: I'm still not seeing anything for this host. Hmmm +.. Maybe it's a Wintel box? Lets try that..\n"; $clientName = $ARGV[ 0 ]; @history = `/usr/openv/netbackup/bin/bpclimagelist -t ANY -client +$clientName -ct 5`; dumpHistory( @history ) if @history; print "Sherlock: No luck.. I'm not seeing anything on it. Trying a +gain, assuming it's a Wintel box AND \"b_\" prefixed..\n"; $clientName = "b_$ARGV[0]"; @history = `/usr/openv/netbackup/bin/bpclimagelist -t ANY -client +$clientName -ct 5`; dumpHistory( @history ) if @history; print "Sherlock: Still no luck. This box needs to be checked manuall +y.\n", "Sherlock: Test results: FAIL\n", "Sherlock: Exiting..\n\n"; } sub dumpHistory { print "Sherlock: Ahhh, there we go. Results! This host appears to +have a backup history..\n"; for my $item ( @_ ) { chomp $item; print "Sherlock: $item\n"; } print "Sherlock: Test results: PASSED\n", "Sherlock: Exiting..\n\n"; exit; }
      Meh. Not nagging at you personally obviously, but I've found that the use of strict and warnings to be more of a pain in the ass than anything generally useful or even pragmatic.. Yeah, I know, blasphemy. I'm far from a god of Perl, but, imho, if you willfully choose to carry the use strict boulder around your neck, you end up unnecessarrily doubling your development time chasing down bugs that aren't really bugs; It's time spent satisfying an unnecessary and optional hurdle, since the code already works as designed. I often wonder if half the stuff I do really justifies the time required to do it....For quickie scripts (like this one) I usually don't bother. Doing something collaborative, however, or mission-critical production level stuff, would be a different story obviously. In those circumstances, i'd consider it useful. Maybe i'm just resentful. :) Thanks for the writeup, anyhoo. :)
        How is @history == NULL not a bug? In this case it works out because NULL isn't defined, but it isn't by design, it is by coincidence.
        Having programmed similar stuff in Perl 4 (pre-strict), I have to disagree; dorking around trying to find the place you misspelled a variable name is a pain in the anatomy. Let the computer show me the dumb mistakes; having to type three more characters to explicitly scope a variable definitely doesn't double my development time, and it definitely halves or quarters my "Why the ^&#$ did it do that?" time.

        Less screwing around with easily-detectable errors means more time for developing fun stuff and blithering on Twitter and Perlmonks. So "yay" for strict, for me.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://755780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-21 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls