#!/usr/bin/perl # Batch EXecutor -- Master Program # (c) 2012--2015 Martin Mares use strict; use warnings; use Getopt::Long; my $bex_home = $ENV{"BEX_HOME"} // "."; my $bex_lib = $ENV{"BEX_LIB"} // "lib"; sub show_help() { print < General options: --home= Home directory where all queues and config files reside --lib= Directory where BEX modules are installed Commands (and aliases): add (a) Add new jobs to a queue help Show this help job (j) Operations on jobs mach List known machines and groups prun (pr) Parallel version of `run' qman Management of queues queue (q) Show queues and jobs on them run (r) Run queued jobs AMEN exit 0; } Getopt::Long::Configure('require_order'); GetOptions( "home=s" => \$bex_home, "lib=s" => \$bex_lib, "help" => \&show_help, "version" => sub { print "BEX 3.3 (c) 2011-2015 Martin Mares \n"; }, ) or die "Try `bex help' for more information.\n"; Getopt::Long::Configure('default'); if (!-d $bex_home) { die "BEX home directory $bex_home does not exist.\n"; } if (!-d "$bex_home/cf") { die "BEX home directory $bex_home does not contain the cf subdirectory.\n"; } if (!-f "$bex_lib/perl/BEX.pm") { die "BEX library directory $bex_lib misconfigured.\n"; } @ARGV or die "Missing subcommand.\n"; my $sub = shift @ARGV; $sub =~ /^[0-9a-zA-Z]+$/ or die "Invalid subcommand $sub\n"; if ($sub eq 'help') { show_help(); } my %aliases = ( 'a' => 'add', 'j' => 'job', 'pr' => 'prun', 'q' => 'queue', 'r' => 'run', ); if (defined $aliases{$sub}) { $sub = $aliases{$sub}; } my $sub_path = "$bex_lib/bin/bex-$sub"; -x $sub_path or die "Unknown subcommand $sub\n"; $ENV{"BEX_HOME"} = $bex_home; $ENV{"BEX_LIB"} = $bex_lib; $ENV{"PERL5LIB"} = join(":", $bex_lib . "/perl", $ENV{"PERL5LIB"} // ()); exec $sub_path, @ARGV; die "Cannot execute $sub_path: $!\n";