#!/etc/Tivoli/bin/perl # # Quick and dirty script to determine who is running Tivoli agents, and who is not. # # Any questions, problems, complaints... # Written by Michael. A. Gumienny # sub connected_to { local($host) = @_; if (!socket(S,2,1,6)) { return 0; } if (!connect(S,pack('Sna4x8',2,6543,pack('C4',split('\.',$host))))) { return 0; } return 1; } sub can_ping { local($host) = @_; open (CMD, "ping -c 1 $host |"); while () { if ($_ =~ "100% packet loss") { close(CMD); return 0; } } close(CMD); return 1; } if ($#ARGV==-1) { printf("Usage: $0 IP_File_List [Agent File] [No Agent File] [Errors]\n"); printf("\tIP_File_List must contain a list of valid IP address to test for Tivoli agent installations.\n"); printf("\tThe 'Agent File' will be a generated listing that contains the IPs that are listening to Tivoli.\n"); printf("\tThe 'No Agent File' is a generated list of IPs that are not running Tivoli or have it turned off.\n"); printf("\tThe 'errors' file will contain any problems encountered while scanning.\n"); exit; } $IPList = shift(@ARGV); $AGFile = shift(@ARGV); $NAFile = shift(@ARGV); $ERFile = shift(@ARGV); open(IPs, "< $IPList") || die "Can't find IP file list '$IPList'\n"; if($AGFile) { open(AGFILE, "> $AGFile") || die "Can't write to $AGFile\n"; } if($NAFile) { open(NAFILE, "> $NAFile") || die "Can't write to $NAFile\n"; } if($ERFile) { open(ERFILE, "> $ERFile") || die "Can't write to $ERFile\n"; } while() { chop; $host = $_; # Ensure that the destination is online before attempting to establish connection... if(&can_ping($host)) { if (&connected_to($host)) { if($AGFile) { printf(AGFILE "$host\n"); } printf("$host Tivoli agent running.\n"); } else { if($NAFile) { printf(NAFILE "$host\n"); } printf("$host *** Is not listening to Tivoli ***\n"); } } else { if($ERFile) { printf(ERFILE "$host\n"); } printf("$host *** Is not online ***\n"); } } if($AGFile) { close(AGFILE); } if($NAFile) { close(NAFILE); } if($ERFile) { close(ERFILE); }