#!/usr/bin/perl use strict; my $nodelist = ""; my $name_base = "odin"; my $name_post = "cs.indiana.edu cpu=2"; my @lst; my $item; my $i_first; my $i_last; my $i; # # Access SLURM_NODELIST Environment variable # $nodelist = `echo \$SLURM_NODELIST`; chomp($nodelist); if(!defined($nodelist) || length($nodelist) <= 0) { print "Not in a slurm allocation. Please run 'salloc' before this command\n"; exit; } #print "Converting <$nodelist>\n"; # # Strip off excess # $nodelist =~ s/^\D+//; $nodelist =~ s/\[//; $nodelist =~ s/\]$//; # # Get ranges # @lst = split(',',$nodelist); foreach $item (@lst) { # # Get the first number $item =~ m/^\d+/; $i_first = $&; if($item =~ s/^\d*-// ) { # # Get the last number $item =~ m/^\d*/; $i_last = $&; } else { $i_last = $i_first; } # # Put the head node in the bhost file # print $name_base; print "." . $name_post . "\n"; # # Add the range to the bhost file # for ( $i = $i_first ; $i <= $i_last ; ++$i) { print $name_base; prec($i); print "." . $name_post . "\n"; } } exit; sub prec(@) { my $dig = shift(@_); # If it starts in 0's, then just print if($dig =~ m/^0+/) { print $dig; } elsif($dig < 10) { print "00" . $dig; } elsif ($dig < 100) { print "0" . $dig; } else { print $dig; } }