Listing 9 srm_instance2project - A perl script to dynamically
move the processes of an instance to a project of the same name
#!/usr/perl5/5.6.1/bin/perl
my $instance=$ARGV[0] || die "Please specify an instance\n";
if ($instance eq "ALL") {
print "Move ALL instances into their projects under FSS? ";
}else{
print "Move instance $instance into project $instance under FSS? ";
}
$answer=<STDIN>;
chomp($answer);
if ( ($answer eq "y") || ($answer eq "Y") ) {
print "This script will move instances to the appropriate project \
based on Oracle 8/9 process naming standards.\n";
}else{
print "No changes made.\n";
exit 99;
}
open(LIST,"ps -u oracle -o args,pid |");
while(<LIST>){
undef $project;
undef $pid;
undef $arg;
undef @stuff;
chomp;
if (($_ =~ /^ora_/) || ($_ =~ /^oracle/)) {
if ( $_ =~ /^ora_/) {
($arg,$pid)=split(/ +/,$_);
@stuff=split(/_/,$arg);
$project=$stuff[2];
}
if ( $_ =~ /^oracle/) {
($arg,$junk,$pid)=split(/ +/,$_);
$project=$arg;
$project =~ s/oracle//g;
}
if (( $project eq $instance ) || ($instance eq "ALL")){
print "Moving process $arg (PID $pid) to project \
$project...\n";
system("newtask -v -p $project -c $pid");
}
}
}
close(LIST);
|