嗯,$MAX为最大节点数,假设qstat得到的占用的节点信息为node123这样的形式。
注意,source了LSF的一些环境变量后会有问题。
#!/usr/bin/perl
use strict;
my $begin_node;
my $end_node;
my $node;
my $USING=`qstat -an | grep node`;
chomp($USING);
my $MAX=384;
sub usage()
{
print "Usage: $0 begin_node end_node\n";
print "Eg.: $0 192 384 [check free node(s) between node192 and node384]\n";
exit;
}
sub my_exit($)
{
print "$_[0]\n";
exit;
}
sub check_opt($$)
{
my $begin = shift;
my $end = shift;
if(("$begin" > "$end") || ("$begin" <= "0") || ("$end" <= "0") || ("$end" > "$MAX"))
{
my_exit("Are you kidding? Please give me a right range of nodes.");
}
else
{
$begin_node = $begin;
$end_node = $end;
}
}
sub free_nodes()
{
print "Free nodes between node $begin_node and $end_node:\n";
for($node = $begin_node; $node < $end_node; $node++)
{
if($node < 10)
{
if($USING !~ /node00$node\/0/)
{
print "node00$node\/0\n";
}
if($USING !~ /node00$node\/1/)
{
print "node00$node\/1\n";
}
}
elsif($node < 100)
{
if($USING !~ /node0$node\/0/)
{
print "node0$node\/0\n";
}
if($USING !~ /node0$node\/1/)
{
print "node0$node\/1\n";
}
}
elsif($node < $MAX)
{
if($USING !~ /node$node\/0/)
{
print "node$node\/0\n";
}
if($USING !~ /node$node\/1/)
{
print "node$node\/1\n";
}
}
else
{
my_exit("Do you have so many nodes? Please change \$MAX in the beginning of this script.");
}
}
}
if( not defined($ARGV[0]) || not defined ($ARGV[1]))
{
usage();
}
check_opt($ARGV[0],$ARGV[1]);
if("$USING" eq "")
{
my_exit("I can't find any free node!");
}
else
{
free_nodes();
}
阅读(7710) | 评论(0) | 转发(0) |