Index: trunk/ippScripts/scripts/sc_remote_exec.pl
===================================================================
--- trunk/ippScripts/scripts/sc_remote_exec.pl	(revision 38062)
+++ trunk/ippScripts/scripts/sc_remote_exec.pl	(revision 38168)
@@ -13,13 +13,4 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
-
-# Hard coded values
-my $DMZ_HOST = 'wtrw';
-my @SEC_HOSTS= ('mu-fe1','mu-fe2','mu-fe3'
-		# ,'mu-fe4'
-    );
-my $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; # 'mu-fe';
-my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
-my $remote_root  = '/scratch3/watersc1/';
 
 # tools
@@ -28,4 +19,5 @@
 my $scp        = can_run('scp')  or (warn "Can't find scp" and $missing_tools = 1);
 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 
 if ($missing_tools) {
@@ -35,5 +27,5 @@
 
 # Options
-my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera);
+my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera,$cmd_recipe);
 $verbose = 0;
 GetOptions(
@@ -42,4 +34,5 @@
     'camera=s'      => \$camera,
     'dbname=s'      => \$dbname,
+    'recipe=s'       => \$cmd_recipe,
     'verbose'       => \$verbose,
     'no_update'     => \$no_update,
@@ -47,7 +40,69 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --remote_id --path_base", -exitval => 3) unless
+pod2usage( -msg => "Required options: --remote_id --path_base --recipe", -exitval => 3) unless
     defined($path_base) and
+    defined($camera) and
+    defined($cmd_recipe) and
+    defined($dbname) and
     defined($remote_id);
+
+# Hard coded values
+# Now accessible from a recipe
+my %remote_recipe = ();
+{
+    my $verbose = 0;
+    my $conf_cmd = "$ppConfigDump -dump-recipe REMOTE -";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $conf_cmd, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppConfigDump: $error_code", -1, $PS_EXIT_SYS_ERROR);
+    }
+    my $mdcParser = PS::IPP::Metadata::Config->new;
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
+
+    my $active_recipe = '';
+    my %recipes = ();
+    
+#    print Dumper($metadata);
+    foreach my $entry (@{ $metadata }) {
+        if (${ $entry }{name} eq 'ACTIVE') {
+            $active_recipe = ${ $entry }{value}; # Not actually used
+        }
+        else {
+            if (${ $entry }{class} eq 'metadata') { # A real recipe
+                my $name = ${ $entry }{name};
+                foreach my $tentry (@{ ${ $entry }{value} }) {
+                    if (${ $tentry }{class} eq 'scalar') { # A recipe value
+                        $recipes{$name}{${ $tentry }{name}} = ${ $tentry }{value};
+                    }
+                    elsif (${ $tentry }{class} eq 'metadata') { # A recipe array 
+                        foreach my $arr_entry (@{ ${ $tentry }{value} }) {
+                            push @{ $recipes{$name}{${ $tentry }{name}} }, ${ $arr_entry }{value};
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    unless (exists($recipes{$cmd_recipe})) { &my_die("Cannot find recipe $cmd_recipe", -1, $PS_EXIT_CONFIG_ERROR) };
+#    print Dumper(%recipes);
+    %remote_recipe = %{ $recipes{$cmd_recipe} }; # Select the appropriate recipe.
+#    print Dumper(\%remote_recipe);
+}
+
+# Hard coded values
+my $DMZ_HOST = $remote_recipe{DMZ_HOST};
+my @SEC_HOSTS= @{ $remote_recipe{SEC_HOST} };
+my $SEC_HOST;
+if ($#SEC_HOSTS != -1) {
+    $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; 
+}
+else {
+    $SEC_HOST = '';
+}
+my $IPP_PATH = $remote_recipe{IPP_PATH};
+my $remote_root  = $remote_recipe{REMOTE_ROOT};
 
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
@@ -141,5 +196,11 @@
     my $file = shift;
     my $destination = shift;
-    my $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
+    my $cmd;
+    if ($SEC_HOST ne '') {
+	$cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
+    }
+    else {
+        $cmd = "$ssh -n $DMZ_HOST $cmd";
+    }
 
     my $directory = dirname($destination);
@@ -157,6 +218,11 @@
     my $destination = shift;
     my $file = shift;
-
-    my $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
+    my $cmd;
+    if ($SEC_HOST ne '') {
+	$cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
+    }
+    else {
+        $cmd = "$ssh -n $DMZ_HOST $cmd";
+    }
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -170,5 +236,11 @@
 sub ssh_exec_command {
     my $cmd = shift;
-    $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
+    if ($SEC_HOST ne '') {
+	$cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
+    }
+    else {
+        $cmd = "$ssh -n $DMZ_HOST $cmd";
+    }
+
     print "EXEC: $cmd\n";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
