Listing 8 srm_apply_project - A perl script to dynamically
apply project settings
#!/usr/perl5/5.6.1/bin/perl
use strict;
use warnings;
use Getopt::Long;
Getopt::Long::config(qw( auto_abbrev bundling bundling_override ));
use vars qw(%opt);
GetOptions(\%opt, qw( --yes2all|y --project|p=s));
my $doit=0;
open (PROJECT, "/etc/project" ) or die "\nERROR: Could not open /etc/project.\n";
while ( <PROJECT> ) {
chomp;
my ($project,$prid,$comment,$user,$group,$limits)= split(/:/);
if ($opt{'project'}) {
if ($project ne $opt{'project'}) {
next;
}
}
if ($limits =~ /(project.cpu-shares=\(.*\))/) {
my @temp=split(/,/,$1);
my $shares=$temp[1];
if ($opt{'yes2all'}) {
$doit=1;
}else{
$doit=yon("Change $project cpu-shares to \
$shares?");
}
if ($doit) {
print "Executing: prctl -r -n \
project.cpu-shares -v $shares \
-i project $project\n";
system("prctl -r -n project.cpu-shares \
-v $shares -i project $project");
}
}
if (($limits =~ /(project.pool=\w*)$/) || \
($limits =~ /(project.pool=\w*),/)) {
my @temp=split(/=/,$1);
my $pool=$temp[1];
if ($opt{'yes2all'}) {
$doit=1;
}else{
$doit=yon("Bind $project to $pool?");
}
if ($doit) {
print "Executing: poolbind -i projid \
-p $pool $project\n";
system("poolbind -i projid -p $pool $project");
}
}
}
sub yon {
my $question = $_[0];
my $answer="";
print "\n$question (yes or no) : ";
while ($answer eq "") {
my $in=<STDIN>;
chomp($in);
$answer=lc($in);
if ( ($answer eq "y") || ($answer eq "yes") ) {
return 1;
}else{
if ( ($answer eq "n") || ($answer eq "no") ) {
return 0;
}else{
print "\nPlease answer yes or no: ";
$answer="";
}
}
}
}
|