#!/usr/bin/perl
use strict;
my $begin_node;
my $end_node;
my $node;
my $bash_env=`. /usr/local/lsf/conf/profile.lsf`;
my $USING=`bjobs -u all | grep node | grep -v "^\$"`;
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"))
{
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/)
{
print "node00$node\n";
}
}
elsif($node < 100)
{
if($USING !~ /node0$node/)
{
print "node0$node\n";
}
}
elsif($node < $MAX)
{
if($USING !~ /node$node/)
{
print "node$node\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();
}
阅读(1690) | 评论(0) | 转发(0) |