Index: /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl
===================================================================
--- /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl	(revision 37268)
+++ /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl	(revision 37269)
@@ -1,3 +1,3 @@
-#!/usr/bin/env perl 
+#!/usr/bin/env perl
 
 use Carp;
@@ -54,5 +54,5 @@
 
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
-my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files                                    
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
 # Phase 1: See if we can actually do anything.
@@ -69,10 +69,10 @@
 unless ($rt_success) {
     $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR);
-    &my_die("UNable to run remotetool to determine remote run status",
-	    $remote_id,$rt_error_code);
-}
-my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or 
-    &my_die("UNable to run remotetool to determine remote run status",
-	    $remote_id,$rt_error_code);
+    &my_die("Unable to run remotetool to determine remote run status",
+            $remote_id,$rt_error_code);
+}
+my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or
+    &my_die("Unable to run remotetool to determine remote run status",
+            $remote_id,$rt_error_code);
 my $rrData2 = parse_md_list($rrData);
 my $runData = ${ $rrData2 }[0]; # There should be only one
@@ -83,5 +83,5 @@
 # Copy command files
     my @files = ();
-    
+
     my $uri_command = $path_base . ".cmd";
     my $uri_transfer= $path_base . ".transfer";
@@ -97,5 +97,5 @@
     my $disk_generate= $ipprc->file_resolve($uri_generate);
     my $disk_return  = $ipprc->file_resolve($uri_return);
-    
+
     scp_put($disk_command,uri_local_to_remote($uri_command));
     scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
@@ -104,5 +104,5 @@
     scp_put($disk_generate,uri_local_to_remote($uri_generate));
     scp_put($disk_return, uri_local_to_remote($uri_return));
-    
+
 # Run check command
     my (undef,$remote_check) = uri_convert($uri_check);
@@ -112,5 +112,5 @@
     # We no longer need to parse this output, as it retrieves files itself.
     foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
-	print "$l\n";
+        print "$l\n";
     }
 
@@ -119,11 +119,11 @@
     my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
     if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
-	$job_id = ${ $ssh_exec_stdout }[0];
-	chomp($job_id);
-	$job_id =~ s/\s+//g;
+        $job_id = ${ $ssh_exec_stdout }[0];
+        chomp($job_id);
+        $job_id =~ s/\s+//g;
     }
 
     unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
-	&my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
+        &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
     }
 
@@ -133,7 +133,8 @@
     $command .= " -job_id $job_id ";
     $command .= " -dbname $dbname " if defined $dbname;
-    
+
+    print STDERR "$command\n";
     system($command);
-    
+
 } # End of exec phase
 
@@ -158,17 +159,17 @@
 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) {
     if ($verbose) {
-	print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
+        print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
     }
     unless ($poll_count == 0) {
-	sleep($poll_sleep);
+        sleep($poll_sleep);
     }
     ($poll_response,$poll_word) = poll_job($job_id);
 
     if ($poll_response == 1) { # This job has completed
-	last;
+        last;
     }
     elsif ($poll_response == -1) { # This job has an error
-	warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
-	$poll_response = 1; # To fool the check later into proceding
+        warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
+        $poll_response = 1; # To fool the check later into proceding
     }
     $poll_count++;
@@ -201,6 +202,6 @@
     push @returned_files, $_;
     if ($_ =~ /dbinfo/) {
-	push @dbinfo_files, $_;
-	push @dbindex, $iter;
+        push @dbinfo_files, $_;
+        push @dbindex, $iter;
     }
     $iter++;
@@ -218,16 +219,16 @@
 # Feed the return list into the transfer tool
 # If this fails, we should go to an auth wait point.
-if ($poll_word eq 'Completed') {  
+if ($poll_word eq 'Completed') {
     # We're complete.  All files should exist on disk
     my $iter = 0;
     my $transfer_success = 1;
     do {
-	$transfer_success = 1;
-	$iter++;
-	check_ssh_connection(); 
-	my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
-	my $return_push_output_print = join "\n", @{ $return_push_output };
-	if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
-	print "$return_push_output_print\n";
+        $transfer_success = 1;
+        $iter++;
+        check_ssh_connection();
+        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
+        my $return_push_output_print = join "\n", @{ $return_push_output };
+        if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
+        print "$return_push_output_print\n";
     } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
 }
@@ -247,14 +248,14 @@
     $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $cmd, verbose => $verbose);
+        run(command => $cmd, verbose => $verbose);
     unless ($success) {
 
-	# This shouldn't fail, but we also can't suddenly abort if something does fail.  
-	# Now we're going to drop the component that owns this dbinfo, which should force a retry.
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
-	if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
-	    drop_component($remote_id,$cmd,$file);
-	}
+        # This shouldn't fail, but we also can't suddenly abort if something does fail.
+        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
+        if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
+            drop_component($remote_id,$cmd,$file);
+        }
     }
 
@@ -272,8 +273,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $cmd, verbose => $verbose);
+        run(command => $cmd, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Authorization check failed.",$remote_id,0,'auth');
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Authorization check failed.",$remote_id,0,'auth');
     }
 }
@@ -288,8 +289,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $cmd, verbose => $verbose);
+        run(command => $cmd, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die(); 
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die();
     }
 }
@@ -302,8 +303,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $cmd, verbose => $verbose);
+        run(command => $cmd, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die(); 
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die();
     }
 }
@@ -314,13 +315,13 @@
     print "EXEC: $cmd\n";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $cmd, verbose => $verbose);
+        run(command => $cmd, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	# If we failed, see if we failed due to authorization.
-	check_ssh_connection(); 
-	&my_die("Failed to execute command: >>$cmd<<"); 
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        # If we failed, see if we failed due to authorization.
+        check_ssh_connection();
+        &my_die("Failed to execute command: >>$cmd<<");
     }
     return ($stdout_buf);
-}    
+}
 
 sub poll_job {
@@ -328,19 +329,19 @@
     my $response_array = ssh_exec_command("checkjob -v $job_id");
     my $response = join "\n", @$response_array;
-    
-    if ($response =~ /State: Running/) { 
-	return(0,"Running");
+
+    if ($response =~ /State: Running/) {
+        return(0,"Running");
     }
     elsif ($response =~ /State: Completed/) {
-	return(1,"Completed");
+        return(1,"Completed");
     }
     elsif ($response =~ /State: Idle/) {
-	return(-2,"Idle");
+        return(-2,"Idle");
     }
     else {
-	my $response_word = $response;
-	$response_word =~ s/.*State: //;
-	$response_word =~ s/\n.*//;
-	return(-1,$response_word);
+        my $response_word = $response;
+        $response_word =~ s/.*State: //;
+        $response_word =~ s/\n.*//;
+        return(-1,$response_word);
     }
 }
@@ -351,7 +352,7 @@
     my $ipp_disk= $ipprc->file_resolve( $neb_uri );
     my $remote_disk = $ipp_disk;
-    
+
     unless(defined($ipp_disk)) {
-	my_die();
+        my_die();
     }
 
@@ -382,5 +383,5 @@
     return($remote_uri);
 }
- 
+
 sub uri_remote_to_local {
     # This needs to replace the remote root directory with the nebulous tag.
@@ -388,5 +389,5 @@
     $remote_uri =~ s%${remote_root}%%;
     my $local_uri  = "neb:///" . $remote_uri;
-    
+
     return($local_uri);
 }
@@ -397,28 +398,28 @@
     my $file = shift;
 
-    if ($cmd eq '') { 
-	# Zero byte file.  This dbinfo was never constructed properly.
-	
-	# Steal the stage_id from the filename.  This isn't something I'm happy about.
-	my $stage = $runData->{stage};
-	my $stage_id = $file;
-	if ($stage eq 'chip') { 
-	    $stage_id =~ s/^.*ch\.//;
-	}
-	elsif ($stage eq 'camera') {
-	    $stage_id =~ s/^.*cm\.//;
-	}
-	elsif ($stage eq 'warp') {
-	    $stage_id =~ s/^.*wrp\.//;
-	}
-	elsif ($stage eq 'stack') {
-	    $stage_id =~ s/^.*stk\.//;
-	}
-	$stage_id =~ s/\..*$//;
-	
-	# Drop this from the database
-	my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
-	$drop_cmd   .= " -dbname $dbname " if defined($dbname);
-	system($drop_cmd);
+    if ($cmd eq '') {
+        # Zero byte file.  This dbinfo was never constructed properly.
+
+        # Steal the stage_id from the filename.  This isn't something I'm happy about.
+        my $stage = $runData->{stage};
+        my $stage_id = $file;
+        if ($stage eq 'chip') {
+            $stage_id =~ s/^.*ch\.//;
+        }
+        elsif ($stage eq 'camera') {
+            $stage_id =~ s/^.*cm\.//;
+        }
+        elsif ($stage eq 'warp') {
+            $stage_id =~ s/^.*wrp\.//;
+        }
+        elsif ($stage eq 'stack') {
+            $stage_id =~ s/^.*stk\.//;
+        }
+        $stage_id =~ s/\..*$//;
+
+        # Drop this from the database
+        my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
+        $drop_cmd   .= " -dbname $dbname " if defined($dbname);
+        system($drop_cmd);
     }
 
@@ -434,13 +435,13 @@
 
     carp($msg);
-    
+
     if (defined $id and not $no_update) {
-	my $command = "$remotetool -updaterun -remote_id $id";
-	$command .= " -fault $exit_code " if defined $exit_code;
-	$command .= " -job_id $job_id " if defined $jobid;
-	$command .= " -set_state $exit_state " if defined $exit_state;
-	$command .= " -dbname $dbname " if defined $dbname;
-
-	system($command);
+        my $command = "$remotetool -updaterun -remote_id $id";
+        $command .= " -fault $exit_code " if defined $exit_code;
+        $command .= " -job_id $job_id " if defined $jobid;
+        $command .= " -set_state $exit_state " if defined $exit_state;
+        $command .= " -dbname $dbname " if defined $dbname;
+
+        system($command);
     }
 
