coding_new has asked for the wisdom of the Perl Monks concerning the following question:
XML Code below#!/usr/local/bin/perl use XML::Twig; use Net::Telnet(); $db = "hrdm2"; $comm = "stop-$db.sh"; $cachedel = "No"; my $s= new XML::Twig( TwigHandlers=> { Product => \&product}); $s->parsefile( 'testservers2.xml'); exit; sub product { my ($s, $product)= @_; my %product; $product{id}= $product->field( 'ServerID'); $product{name}= $product->field( 'DBName'); $product{commandstop}= $product->field( 'CommandStop'); $product{commandstart}= $product->field( 'CommandStart'); $product{cache}= $product->field( 'CacheDir'); if ($db eq $product{name} && $comm eq $product{commandstop} && $ +cachedel eq 'No') { print "DB Name: $product{name}\n" ; print "Command: $product{commandstop}\n"; print "Server: $product{id}\n"; print "Cache Dir:$product{cache}\n"; print "Cache Del: No\n"; $pass = "pass"; $t = new Net::Telnet (Timeout => 500); $t->open("$product{id}"); $t->login('root', $pass); @lines = $t->cmd("cd /apps/gcpsscripts"); @lines = $t->cmd("ls"); @lines = $t->cmd("sh $product{commandstop}"); print @lines; $product->delete; } elsif ($db eq $product{name} && $comm eq $product{commandstop} && +$cachedel eq 'Yes') { print "DB Name: $product{name}\n" ; print "Command: $product{commandstop}\n"; print "Server: $product{id}\n"; print "Cache Dir:$product{cache}\n"; print "Cache Del: Yes\n"; $pass = "pass"; $t = new Net::Telnet (Timeout => 500); $t->open("$product{id}"); $t->login('root', $pass); @lines = $t->cmd("cd /apps/gcpsscripts"); @lines = $t->cmd("ls"); @lines = $t->cmd("sh $product{commandstop}"); print @lines; $product->delete; } elsif ($db eq $product{name} && $comm eq $product{commandstart}) { print "DB Name: $product{name}\n" ; print "Command: $product{commandstart}\n"; print "Server: $product{id}\n"; $pass = "pass"; $t = new Net::Telnet (Timeout => 500); $t->open("$product{id}"); $t->login('root', $pass); @lines = $t->cmd("cd /apps/gcpsscripts"); @lines = $t->cmd("ls"); @lines = $t->cmd("sh $product{commandstart}"); print @lines; $product->delete; } open (LOGFILE, '>>C:\\temp\\stopstart.log') or die "Can't open + log file.\n"; print LOGFILE "\n"; print LOGFILE "@lines \n"; print LOGFILE "\n"; close LOGFILE; }
<?xml version='1.0'?> <Products> <Product> <DBName>hrdm2</DBName> <ServerID>psdevax03</ServerID> <CommandStop>stop-hrdm2.sh</CommandStop> <CommandStart>start-hrdm2.sh</CommandStart> <CacheDir>/apps/846hrdm2/appserv/hrdm2/CACHE</CacheDir> </Product> <Product> <DBName>hrdev</DBName> <ServerID>psdevax06</ServerID> <CommandStop>stop-hrdev.sh</CommandStop> <CommandStart>start-hrdev.sh</CommandStart> <CacheDir>/apps/846hrdev/appserv/hrdev/CACHE</CacheDir> </Product> <Product> <DBName>epdev</DBName> <ServerID>psdevax06</ServerID> <CommandStop>stop-epdev.sh</CommandStop> <CommandStart>start-epdev.sh</CommandStart> <CacheDir>/apps/846epdev/appserv/epdev/CACHE</CacheDir> </Product> <Product> <DBName>eptst</DBName> <ServerID>psdevax06</ServerID> <CommandStop>stop-eptst.sh</CommandStop> <CommandStart>start-eptst.sh</CommandStart> <CacheDir>/apps/846eptst/appserv/eptst/CACHE</CacheDir> </Product> </Products>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl code looping using XML::Twig
by roubi (Hermit) on Apr 21, 2009 at 00:01 UTC | |
by coding_new (Sexton) on Apr 21, 2009 at 01:23 UTC | |
|
Re: Perl code looping using XML::Twig
by toolic (Bishop) on Apr 21, 2009 at 00:45 UTC | |
|
Re: Perl code looping using XML::Twig
by edoc (Chaplain) on Apr 20, 2009 at 23:53 UTC | |
|
Re: Perl code looping using XML::Twig
by fawzi (Initiate) on Apr 21, 2009 at 03:44 UTC |