Background:
I was to read the NetAgent configuration file and determine if the server is an MDH or P2PS (this is about RMDS). Another was from the RMDS config file to do the same, which means I got to make two.
Apologies but I cannot post config files here. But I believe you can easily understand how it process things.
Here is the code - as a standalone:
sub inNetAgentConfig {
my $host = shift;
my $conf_file = "/path/to/config.file";
open FH, $conf_file or die "Error: $!\n";
$/ = "ATTRIBUTES"; # set the line delimiter to ATTRIBUTES instead of default value of newline; see special variables
my @array = <FH>;
if ( grep {/$host/} $conf_file ) {
foreach my $line ( grep {/$host/} @array ) {
if ( $line =~ /GROUP=(\w+)/ ) {
return $1;
}
}
} else {
return "Non-existent";
}
}
} else {
return "Non-existent";
}
}
Another function that I made:
sub inRmdsConfig {
my $host = shift;
my $rmds_file = "/path/to/config.file";
open FILE, $rmds_file or die "Error: $!\n";
while (<FILE>) {
chomp ( $_ );
if ( $_ =~ /^$host\*(\w+)\*serverId.?/ ) {
return $1;
} else {
return "Non-existent";
}
}
No comments:
Post a Comment