Quickly Add a Userset to Many Sun Grid Engine Queues

This will be the first (of many??) posts to spill outside the topics one would think you’d find on a site with the name “Your Mac Guy”. You’ve been warned.

Back in January (of 2009) my primary work responsibilities shifted from Mac servers and desktops (and all that entailed) to Linux servers and desktops and the multitude of new things that entails (at least here where I work). One of the new tasks I’ve picked up is user administration of our Sun Grid Engine (SGE) 500-node cluster. New or existing users who want to submit jobs to the cluster need to be added to custom groups or, in SGE-speak, usersets. We create usersets for each lab, so if the user is part of a lab that doesn’t currently have access to submit jobs, I need to create a new userset and add that userset to each of 16 separate queues.

That last part, adding usersets to queues, is the most tedious part. So tedious, in fact, that it forced my hand into developing a scripted solution. I likely could have found an existing script to accomplish the task for me, but then I wouldn’t have had an excuse to brush up on my 3-years dormant perl skills.

With the help of a perl book, a dash of google, a short debugging session, and the successful execution of the product on our production cluster, I bring you the following code. I welcome any and all suggestions for improvement and general verbal lashings for poor form. Please note, if you intend to try it, modify the @queues array to suit.

#!/usr/bin/perl -w
use strict;
# This script automates the process of adding usersets to the user_lists section
# of the SGE cluster queue configs. It takes the userset name as a command line
# argument or it prompts for the userset name if no argument is given. Multiple
# lists can be submitted as a comma-separated list *without spaces*.
# queues to be modified
my @queues = qw(
my $input=$ARGV[0];
# If no arguments passed, print helpful info and prompt for userset name
if (! defined($input)) {
print join( "\n ", "\nThis command will add a new userset to the following cluster queues:\n" , @queues , "\n" );
# Get input from STDIN.
print "Enter the name of the new userset (or ^c to exit). Use commas *without spaces* to separate multiple lists): ";
# Add the supplied usersets to each queue using 'qconf -aattr' method
foreach my $queue (@queues) {
system("qconf -aattr queue user_lists $input $queue");

view raw
hosted with ❤ by GitHub