Changeset 38168 for trunk/ippScripts/scripts/sc_remote_exec.pl
- Timestamp:
- Apr 23, 2015, 3:12:58 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/sc_remote_exec.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/sc_remote_exec.pl
r38062 r38168 13 13 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 14 14 use Pod::Usage qw( pod2usage ); 15 16 # Hard coded values17 my $DMZ_HOST = 'wtrw';18 my @SEC_HOSTS= ('mu-fe1','mu-fe2','mu-fe3'19 # ,'mu-fe4'20 );21 my $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; # 'mu-fe';22 my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';23 my $remote_root = '/scratch3/watersc1/';24 15 25 16 # tools … … 28 19 my $scp = can_run('scp') or (warn "Can't find scp" and $missing_tools = 1); 29 20 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 21 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 30 22 31 23 if ($missing_tools) { … … 35 27 36 28 # Options 37 my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera );29 my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera,$cmd_recipe); 38 30 $verbose = 0; 39 31 GetOptions( … … 42 34 'camera=s' => \$camera, 43 35 'dbname=s' => \$dbname, 36 'recipe=s' => \$cmd_recipe, 44 37 'verbose' => \$verbose, 45 38 'no_update' => \$no_update, … … 47 40 48 41 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 49 pod2usage( -msg => "Required options: --remote_id --path_base ", -exitval => 3) unless42 pod2usage( -msg => "Required options: --remote_id --path_base --recipe", -exitval => 3) unless 50 43 defined($path_base) and 44 defined($camera) and 45 defined($cmd_recipe) and 46 defined($dbname) and 51 47 defined($remote_id); 48 49 # Hard coded values 50 # Now accessible from a recipe 51 my %remote_recipe = (); 52 { 53 my $verbose = 0; 54 my $conf_cmd = "$ppConfigDump -dump-recipe REMOTE -"; 55 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 56 run(command => $conf_cmd, verbose => $verbose); 57 unless ($success) { 58 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 59 &my_die("Unable to perform ppConfigDump: $error_code", -1, $PS_EXIT_SYS_ERROR); 60 } 61 my $mdcParser = PS::IPP::Metadata::Config->new; 62 my $metadata = $mdcParser->parse(join "", @$stdout_buf); 63 64 my $active_recipe = ''; 65 my %recipes = (); 66 67 # print Dumper($metadata); 68 foreach my $entry (@{ $metadata }) { 69 if (${ $entry }{name} eq 'ACTIVE') { 70 $active_recipe = ${ $entry }{value}; # Not actually used 71 } 72 else { 73 if (${ $entry }{class} eq 'metadata') { # A real recipe 74 my $name = ${ $entry }{name}; 75 foreach my $tentry (@{ ${ $entry }{value} }) { 76 if (${ $tentry }{class} eq 'scalar') { # A recipe value 77 $recipes{$name}{${ $tentry }{name}} = ${ $tentry }{value}; 78 } 79 elsif (${ $tentry }{class} eq 'metadata') { # A recipe array 80 foreach my $arr_entry (@{ ${ $tentry }{value} }) { 81 push @{ $recipes{$name}{${ $tentry }{name}} }, ${ $arr_entry }{value}; 82 } 83 } 84 } 85 } 86 } 87 } 88 89 unless (exists($recipes{$cmd_recipe})) { &my_die("Cannot find recipe $cmd_recipe", -1, $PS_EXIT_CONFIG_ERROR) }; 90 # print Dumper(%recipes); 91 %remote_recipe = %{ $recipes{$cmd_recipe} }; # Select the appropriate recipe. 92 # print Dumper(\%remote_recipe); 93 } 94 95 # Hard coded values 96 my $DMZ_HOST = $remote_recipe{DMZ_HOST}; 97 my @SEC_HOSTS= @{ $remote_recipe{SEC_HOST} }; 98 my $SEC_HOST; 99 if ($#SEC_HOSTS != -1) { 100 $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; 101 } 102 else { 103 $SEC_HOST = ''; 104 } 105 my $IPP_PATH = $remote_recipe{IPP_PATH}; 106 my $remote_root = $remote_recipe{REMOTE_ROOT}; 52 107 53 108 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); … … 141 196 my $file = shift; 142 197 my $destination = shift; 143 my $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}"; 198 my $cmd; 199 if ($SEC_HOST ne '') { 200 $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}"; 201 } 202 else { 203 $cmd = "$ssh -n $DMZ_HOST $cmd"; 204 } 144 205 145 206 my $directory = dirname($destination); … … 157 218 my $destination = shift; 158 219 my $file = shift; 159 160 my $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file "; 220 my $cmd; 221 if ($SEC_HOST ne '') { 222 $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file "; 223 } 224 else { 225 $cmd = "$ssh -n $DMZ_HOST $cmd"; 226 } 161 227 162 228 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 170 236 sub ssh_exec_command { 171 237 my $cmd = shift; 172 $cmd = "$ssh -n $DMZ_HOST ssh ${SEC_HOST} $cmd"; 238 if ($SEC_HOST ne '') { 239 $cmd = "$ssh -n $DMZ_HOST ssh ${SEC_HOST} $cmd"; 240 } 241 else { 242 $cmd = "$ssh -n $DMZ_HOST $cmd"; 243 } 244 173 245 print "EXEC: $cmd\n"; 174 246 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Note:
See TracChangeset
for help on using the changeset viewer.
