Hello about 2 days ago our ping script started generating errors during the running of the script Error shown:
Checking "devicename"... alive Use of uninitialized value in split at +script/ping2.pl line 74, <IN> line 17 Use of uninitialized value $NBTHost in string eq at script.ping2.pl li +ne 76 <IN> . line 17 Not unique Use of uninitialized value $NBTHost in concatenation <.> or string at +script/ping2.pl line 97, <IN> line 17.
I am a novice when it comes to this so any help would be appriciated This is the full script
#!/usr/bin/env perl use warnings; use strict; # # Author: # # 2011(C) # # Change History # 0.1 Initial Release # 0.2 20150109.01 Added epoport.txt file to pass ePO po +rt # # Description: Reads list of server names by their host names, checks +to see if # they are alive via ping, completes an nbtstat -a and returns any lin +es containing # the host name and then checks to see if ePO port is open on the aliv +e system. # # Input: # srvlst.txt containing one hostname per line # epoport.txt containing ePO port # # Output: # PingResults.csv # Format: Hostname, IP address, Alive status (Yes|No|Unknown Ho +st|Unreachable|Unknown status), NBTSTAT result (NUL|$hostname), ePO p +ort status (Open|closed) my $epoport = ''; my $socket = ""; my $hostcnt = 0; open (my $conf, '<epoport.txt') or die "Run aborted. Cannot open the e +PO port file (epoport.txt)"; while(<$conf>) { my $line = $_; chomp($line); ($epoport) = split(",", $line); }; close ($conf); print "ePO port: $epoport\n\n"; open (IN, "<srvlst.txt") or die "Run aborted. Cannot open endpoint lis +t file (srvlst.txt)"; open (OUT, ">PingResults.csv") or die "Run aborted. Unable to open res +ult file (PingResults.csv)"; print OUT "Hostname,IP,Alive,NBTHost,Port $epoport\n"; print "Start to check hosts\n"; while (<IN>) { my $HOST = $_; chomp $HOST; print "Checking $HOST... "; my $IP = ''; my $NBTHost = ''; my $Alive = 'No'; my $ePOPort = 'Closed'; my $out = ""; ++$hostcnt; my $PingReply = `PING -n 1 -w 1 $HOST`; if ($PingReply =~ /unreachable/) { print "unreachable\n"; $Alive = 'Unreachable'; } elsif ($PingReply =~ /Reply from/) { $Alive = 'Yes'; print "alive "; my @Temp = split / /, $PingReply; $IP = $Temp[2]; $IP =~ s/\[//g; $IP =~ s/\]//g; my $NBTResults = `nbtstat -a $IP | find \"UNIQUE\"`; while (index($NBTResults,' ') > -1) { $NBTResults =~ s/ / /g; } my @NBTResults = split /\n/, $NBTResults; # We only need the first returned hostname of the NBT results +(they're usually duplicates) my @LineTemp = split / /, $NBTResults[0]; $NBTHost = $LineTemp[1]; if ($NBTHost eq $HOST) { $NBTHost = ''; print "unique\n"; # Check ePO open port my $epoResponse = CheckPort($HOST,$epoport); if ($epoResponse == 1) { $ePOPort = "Open"; } else { $ePOPort = "Closed"; }; } else { print "Not unique\n"; $Alive = 'Unknown status'; } } elsif ($PingReply =~ /could not find host/) { print "unknown\n"; $Alive = 'Unknown host'; } else { print "not alive\n"; $Alive = 'No'; } print OUT "$HOST,$IP,$Alive,$NBTHost,$ePOPort\n"; } close OUT; close IN; print "\nCheck completed. Checked $hostcnt hosts\n"; sub CheckPort { use IO::Socket::INET; my ($host,$port) = @_; my $open = eval{ $socket = new IO::Socket::INET # opens a socket ( PeerAddr => $host, PeerPort => $port, Proto => getprotobyname('tcp') || 6 # tcp socket or sopcket 6(for +old comps) )}; if ($open) { return 1; } else { return 0; } }
thank you

In reply to Ping Script Error running on 64bit server by jlandrig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.