#!/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; }