#!/usr/bin/perl -w #use lib "./"; use strict; use XML::XPath; use XML::XPath::XMLParser; use File::Copy; my $das_domain_dir =""; do { print "Enter the DAS domain directory: "."\n\n"; print "Domain directory name \[For ex. /opt/SUNWappserver/domains/domain1\] : "; $das_domain_dir = ; chomp($das_domain_dir); }until( -e $das_domain_dir); my $parser = new XML::Parser( NoLWP => 0 ); my $domainConfig="$das_domain_dir/config/domain.xml"; my $xpath = XML::XPath->new( parser => $parser, filename => $domainConfig ); my($root) = $xpath->findnodes('/'); my $dasHost =""; print "Enter the value of the logical hostname for DAS \[For ex. cluster-lh\] : "; $dasHost = ; chomp($dasHost); my $httpService="//config[\@name='server\-config']/http-service/http-listener/\@address"; my $iiopService="//config[\@name='server\-config']/iiop-service/iiop-listener/\@address"; my $adminService="//config[\@name='server\-config']/admin-service/jmx-connector/property/\@value"; $xpath->setNodeText($httpService, "$dasHost"); $xpath->setNodeText($iiopService, "$dasHost"); $xpath->setNodeText($adminService, "$dasHost"); my $NodeAgents = $xpath->find( "//node-agents/node-agent/\@name"); my @eachNA; my $noOfNA = 1; my @nodeAgentName; my $na_dir = ""; do { print "Enter the Node agent(s) root directory : "."\n\n"; print "Node agent root directory name \[For ex: /opt/SUNWappserver/nodeagents\] : "; $na_dir = ; chomp($na_dir); }until ( -e $na_dir ); foreach my $node($NodeAgents->get_nodelist) { $nodeAgentName[$noOfNA] = $node->string_value(); print "Enter the value of the logical hostname for $nodeAgentName[$noOfNA] \[For ex.: na-lh\] : "; my $na = ; chomp($na); $xpath->setNodeText( "//node-agents/node-agent[\@name='$nodeAgentName[$noOfNA]']/jmx-connector/property/\@value", "$na"); # open node agent file my $nodePropsFile="$na_dir/$nodeAgentName[$noOfNA]/agent/config/nodeagent.properties"; open F, "< $nodePropsFile" or die "Can't open $nodePropsFile: $!"; $eachNA[$noOfNA] = ""; while () { s/agent.client.host=.*/agent.client.host=$na/g; $eachNA[$noOfNA] = $eachNA[$noOfNA] . $_; } close F; $noOfNA++; } print "\n Do you wish to overwrite the files:[y/n]"; my $ans = <>; chomp($ans); if ("$ans" eq "y") { print "All the files will be backed up with .BKP ext. The .BKP files will be overwritten if you run this script again." . "\n"; copy $domainConfig, $domainConfig.".BKP"; my $omittedData=" \n"; write_file( $domainConfig, $omittedData.$root->toString()); for ( my $i = 1 ; $i< @eachNA; $i++) { my $nodePropsFile="$na_dir/$nodeAgentName[$i]/agent/config/nodeagent.properties"; copy $nodePropsFile, $nodePropsFile.".BKP"; write_file($nodePropsFile, $eachNA[$i]); } } sub write_file { my($f, @data) = @_; @data = () unless @data; open F, "> $f" or die "Can't open $f : $!"; print F @data; close F; }