tsm-group-nodes.pl 4.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/perl

##############################################################################
#
#	tsm-group-nodes.pl
#	
#	script for group former nongroup nodes 
#		to collocgroupr due to their policy domain
#
#	
#
#	(C) 2015,2019 GWD Göttingen, Bjørn Nachtwey
#	    mailto:bjoern.nachtwey@gwdg.de
#
##############################################################################
#
# changelog
# date      	version	remark
# 2015-01-16	0.8	initial coding
# 2015-04-22	0.9	fixes for mon1.tsm.gwdg.de
# 2019-07-31	1.0	switched to common style with account and password given by call
#
##############################################################################

use warnings;
use strict;
use Time::Piece;

##############################################################################
##############################################################################
# F I L L   I N   Y O U R   S E T T I N G S   H E R E
##############################################################################
##############################################################################

##############################################################################
# C R E D E N T I A L S
##############################################################################
my	$admuser 		= $ARGV[0];	# or replace by expicit ID
my	$admpwd 		= $ARGV[1];	# or replace by expicit PW

##############################################################################

# # some loop iterators
my	$server;			# actual server name
my	$server_name;
my	$node_name;
my	$domain_name;


# # some lists to be processed

my 	@serverlist 		= qw /tsm110 tsm112 tsm130 tsm131 tsm180 tsm182 tsm230 tsm231 tsm232 tsm233 tsm234 tsm235 tsm236 tsm237 tsm285/;	# list of new servers

my	@domainlist;		# list of domains
my	@nodelist;		# list of all non-collocated nodes


my	$dsmadmc 		= "/usr/bin/dsmadmc ";	# linux servers
my	$dsmargs 		= " -tab -dataonly=yes -id=$admuser -pa=$admpwd -outfile";
 
my	$date			= localtime->strftime ('%F');
my	$outputpath		= "/TSM/log/";
my	$outlog			= $outputpath . $date . "-grouped-nodes.log";
# 
# # new variables
my	$command;
my	$selectstatement;


open LOGFILE, ">" . $outlog	or die "$0: cannot open log file: " . $outlog;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main loop over all servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

foreach $server (@serverlist)
{

	$server_name		= $server;

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# get list of domains
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
	undef @domainlist;
	
	if ( $server =~ m/-admin$/ )
	{
		$server_name	= $server;
		$server_name	=~ s/-admin$//;
	}
	else
	{
		$server_name	= $server;
	}

	printf LOGFILE "\n ==>\t SERVER: $server_name\n\n";
	printf LOGFILE " ====>\t COLLOCGROUPS \n\n";
	$selectstatement	= "select domain_name from domains minus (select collocgroup_name from collocgroup)";

	$command		= "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";

	@domainlist		= split '\n' , `$command`;


	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# define collocgroup for each domain without default-group
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	foreach my $domain (@domainlist)
	{
		next if ( $domain eq "TPL" );
		next if ( $domain =~ m/^GWDG-FS/ );

		printf LOGFILE "DEF COLLOCGR $domain\n";
		$command	= "$dsmadmc $dsmargs -se=$server \"DEF COLLOCGR $domain\" 2>/dev/null";
		`$command`;
	}	# EO foreach domain

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# get all non-collocated nodes
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	$selectstatement	= "SELECT domain_name, node_name from nodes where (collocgroup_name IS NULL)";

	$command		= "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";

	@nodelist		= split '\n' , `$command`;

	printf LOGFILE "\n ====>\t NODES \n\n";

	foreach my $node (@nodelist)
	{
		if ( ( $node =~ m/^ANR/ ) or ($node =~ m/^ANS/) )
		{
			last
		}
		($domain_name, $node_name) = split '\t' , $node;

		next if ( $domain_name eq "TPL" );
		next if ( $domain_name =~ m/^GWDG-FS/ );

		printf LOGFILE "def collocmem $domain_name $node_name\n";
		$command	= "$dsmadmc $dsmargs -se=$server \"def collocmem $domain_name $node_name\" 2>/dev/null";
		`$command`;
	}

	printf LOGFILE "======================================================================\n";
}

close LOGFILE;