-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_continuations.pl
108 lines (105 loc) · 3.85 KB
/
test_continuations.pl
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
#!/usr/bin/perl -w
#print "Before nsradmin\n";
##$nsrpass = ". type:NSR client'\n'show name\\;group\\;comment\\;action'\n'print";
#$nsrpass = ". type:NSR client'\n'show name\\;group\\;backup command\\;scheduled backup\\;comment\\;action'\n'print";
#(@return) = handle_nsradmin_line_continuations($nsrpass);
#foreach $vvv (@return) {
# print "INFO: $vvv\n";
#}
$print_only=0;
#$ggroup = 'Automated-NON-PROD-Reruns';
#$return = remove_clients_from_group($ggroup);
$ggroup = 'Automated-NON-PROD-VADP-Reruns';
$return = remove_clients_from_group($ggroup);
#$ggroup = 'Automated-PROD-VADP-Reruns';
#$return = remove_clients_from_group($ggroup);
#$ggroup = 'Automated-PROD-Reruns';
#$return = remove_clients_from_group($ggroup);
sub remove_clients_from_group {
($pgroup) = @_;
my $group = $pgroup;
# Find all client in the pgroup
$nsrpass_remove = "\. type: NSR client\\;group:$group'\n'show name\\;group'\n'print'\n'";
(@return) = handle_nsradmin_line_continuations($nsrpass_remove);
#foreach $vvv (@return) {
# print "vvv=$vvv\n";
#}
#
# The return will be client name, and group on the next line
#foreach $val (@return) {
for ($i=0;$i<=$#return;$i++) {
$val=$return[$i];
chomp $val;
if ($val =~ /No resources found for query/) {
# There are no client in the group
undef $client;
return;
}
next if $val =~ /type: NSR client\;/;
next if $val =~ /Current query set/;
next if $val =~ /^\s*$/; # Skip blank Lines
if ($val =~ /name:/) {
($client) = ($val =~ /name: (\S+)\;$/);
$i ++;
$val = $return[$i];
chomp $val;
$val =~ s/^.*group: //;
$val =~ s/$group[, ]*//; # Remove group first location;
$val =~ s/,\s$group//g; # Remove all occurences of the group after the first location;
$nsrpass = "\. type: NSR client\\;name:$client'\n'update group:$val'\n'";
print "NSRPASS in remove_clients_from_group=$nsrpass\n";
if ($print_only == 1) {(@return1) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -i - `};
# foreach $vall (@return1) {
# print "Returned $vall";
#}
} else {
print "*******************************Error**********************************\n";
}
}
}
sub handle_nsradmin_line_continuations {
($nsrpass) = @_;
undef @combined;
my (@return) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -i -`;
$output_rec = 0;
$combined[0] = '';
$continue = 0;
# Do it easy
for ($i = 0;$i<=$#return;$i++) {
chomp $return[$i];
next if $return[$i] =~ /Current query set/;
if ($return[$i] =~ /No resources found for query/) {
$combined[0]="No resources found for query";
goto RETURN;
}
# The addition is to handle multiline groups and there is space between last group and end of line
#if line ends with , instead of ; then we have a continuation
#if ( $return[$i] =~ /\\$/ || $return[$i] =~ /,\s*$/) {
if ( $return[$i] =~ /,\s*$/ ) {
# Current line has a continuation so don't close out
$return[$i] =~ s/\\//;
$continue = 1;
if (defined $combined[$output_rec]) {
$return[$i] =~ s/^\s+//;
$combined[$output_rec] = $combined[$output_rec] . $return[$i];
} else {
$combined[$output_rec] = $return[$i];
}
} else {
if ($continue == 1) {
#working on a record so append it and start new record for next;
$return[$i] =~ s/^\s+//;
$combined[$output_rec] = $combined[$output_rec] . $return[$i];
} else {
$combined[$output_rec] = $return[$i];
}
$output_rec +=1;
$continue = 0;
}
}
undef @return;
#foreach $ppp (@combined) {
# print "In handle:$ppp\n";
#}
RETURN: return @combined;
}