Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1864742
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类:

2006-02-21 13:38:23

嗯,$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) |
给主人留下些什么吧!~~