>From 1ca095299d9be96907c4b318c998d2f8ad143003 Mon Sep 17 00:00:00 2001
From: Matthew Farrellee <matt@redhat.com>
Date: Wed, 5 Jan 2011 10:52:29 -0500
Subject: [PATCH] Add -a to condor_run in the style of condor_submit's -append

Additionally, the shell-cmd is now pieced together from all non dash (-u/-a/-h) arguments on the command line.
---
 src/condor_scripts/condor_run |   62 +++++++++++++++++++++++++---------------
 1 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/src/condor_scripts/condor_run b/src/condor_scripts/condor_run
index 7ca648f..3a9b209 100755
--- a/src/condor_scripts/condor_run
+++ b/src/condor_scripts/condor_run
@@ -40,35 +40,48 @@
 #
 ###########################################################################
 
-# possible universe argument (don't "use Getopt::Std")
-# must be first thing before shell command
-$universe = 'vanilla';
-if ( defined $ARGV[0] ) {
-    if ( $ARGV[0] eq '-u' && defined $ARGV[1] ) {
-	shift;
-	$universe = shift;
-    } elsif ( $ARGV[0] =~ /^-u(.*)/ ) {
-	$universe = $1;
-	shift;
+my @command;
+my @appends;
+my $universe = 'vanilla';
+if (!defined($ARGV[0])) {
+    goto HELP;
+}
+while ( $_ = shift( @ARGV ) ) {
+  SWITCH: {
+      if ( /^-h.*/ ) {
+	HELP:
+	  print "usage: $0 [-u <universe>] [-a command]* \"shell-cmd\"\n";
+	  print "\twhere shell-cmd is any Unix shell statement.\n";
+	  print "\t-u lets you set the universe to which the job is submitted.\n";
+	  print "\t   The default is vanilla.\n";
+	  print "\t-a lets you add additional submit commands\n";
+	  print "\t   e.g. -a request_memory=1024\n";
+	  print "\tEnvironment variables CONDOR_ARCH, CONDOR_OPSYS, and\n";
+	  print "\tCONDOR_REQUIREMENTS may specify remote machine's Arch,\n";
+	  print "\tOpSys, and any additional requirements.\n";
+	  exit 1;
+      }
+      if ( /^-u(.*)/ ) {
+          $universe = $1 ? $1 : shift(@ARGV);
+          next SWITCH;
+      }
+      if ( /^-a.*/ ) {
+          push(@appends, shift(@ARGV));
+          next SWITCH;
+      }
+
+      # Anything passed in that isn't -u or -a is part of the command to run
+      push(@command, $_);
     }
 }
+if (!@command) {
+    goto HELP;
+}
 
 # grab current working directory for initial dir in system using automounter
 $pwd = `pwd`;
 chomp $pwd;
 
-# check arguments
-if (!defined($ARGV[0]) || $ARGV[0] eq "-h" || $ARGV[0] eq "-help") {
-    print "usage: $0 [-u <universe>] \"shell-cmd\"\n";
-    print "\twhere shell-cmd is any Unix shell statement.\n";
-    print "\t-u lets you set the universe to which the job is submitted.\n";
-    print "\t   The default is vanilla.\n";
-    print "\tEnvironment variables CONDOR_ARCH, CONDOR_OPSYS, and\n";
-    print "\tCONDOR_REQUIREMENTS may specify remote machine's Arch,\n";
-    print "\tOpSys, and any additional requirements.\n";
-    exit 1;
-}
-
 # set up environment for running something in the current directory in case
 # they want to run something in the current working directory and they
 # don't specify a "./" infront of it.
@@ -117,7 +130,7 @@ if (defined($opsys)) {
 open(CMD, ">.condor_run.$$") ||
     &abort("Can't create temporary (CMD) file in current directory.\n");
 print CMD "#!", $shell, "\n";
-foreach $arg (@ARGV) {
+foreach $arg (@command) {
     print CMD $arg, " ";
 }
 print CMD "\n";
@@ -138,6 +151,9 @@ print JDF "output = .condor_out.$$\n";
 print JDF "error = .condor_error.$$\n";
 print JDF "getenv = True\n";
 print JDF "requirements = ", $requirements, "\n" if (defined($requirements));
+foreach my $append (@appends) {
+    print JDF $append . "\n";
+}
 print JDF "queue\n";
 close(JDF) ||
     &abort("Failed to write temporary (JDF) file in current directory.\n");
-- 
1.7.3.4

