sub run_ndm { # Set NDM Environment $ENV{NDMBINDIR}=File::Spec::Unix->catdir('/',"opt","cdunix","ndm","bin"); $ENV{NDMAPICFG}=File::Spec::Unix->catfile('/opt',"cdunix","ndm","cfg","cliapi","ndmapi.cfg"); $ENV{PATH}='/bin:/usr/bin:/opt/cdunix/ndm/bin'; my ($file,$process,$dataset,$blocks,$reclength,$recform)=@_; my $log=File::Spec::Unix->catfile('/',"opt","CyberFusion","log","$process.ndm.log"); my $temp=File::Spec::Unix->catfile('/',"opt","CyberFusion","log","$process.temp"); my $pnum; my $return; $dataset="$dataset(+1)" if ($_[6] =~ /G/i); umask 0110; # Printing parameters to log file. print "-" x 30; print qq/ Running with the following parameters... Process: $process File Name: $file NDM File Name: $dataset Record Format(RECFM): $recform Record Length(LRECL): $reclength Block Size(BLKSIZE): $blocks /; print "-" x 30 . "\n"; # executing NDM process system("/opt/cdunix/ndm/bin/ndmcli -x << EOJ >> $log submit $process process snode=XXXXXXXX #snode is the node ID for the destination step01 copy from (file=$file sysopts=\":datatype=text:\" pnode ) compress extended to (file=$dataset DCB=(RECFM=$recform,LRECL=$reclength,BLKSIZE=$blocks,DSORG=PS) SPACE=(CYL,(000050,0000020,),RLSE,,) snode disp=(NEW,CATLG,DELETE) ) step02 if (step01 gt 4) then run task sysopts=\"echo ** File not copied, Abnormal Termination **\" goto stepend eif stepend run task sysopts=\"echo ** Job Ending **\" pend; EOJ"); $|=0; #flush the print buffers sleep 300; #sleep for 300 seconds - may need to be adjusted longer to make sure that the NDM process is complete # Try to open the log file - may want to adjust this to not die if it cannot open the file, but instead sleep for a # specified amount of time (say 60 seconds) to give the file time to transmit open LOGFILE, "$log" or die "Cannot open $log. $!"; #once we get into the log file, we grab the process number to be used in the status check later foreach my $line () { chomp $line; if ($line =~ /mber/) { #pnum=substr($line,-5,5); $pnum=substr($line,36); }#close if }#close inner foreach close LOGFILE; # next we will fire up the ndmcli again and dump it out to a temporary file. system("/opt/cdunix/ndm/bin/ndmcli -x << EOJ >> $temp select statistics pnumber=($pnum) detail=YES; q; EOJ"); $|=0; #flush the buffers # now that we have the status dumped to a temp file, we have to parse it. # to find the Completion codes. open TEMP, "$temp" or die "Cannot open $temp. $!"; # Scan each line for "Ccode" # using backreferences on the 'ccode' line, pull out the return codes. # these return codes represent the source and destination completion codes for both ends of the process # Both sides are added together to get one number ($return). foreach my $line () { chomp $line; if ($line =~ /Ccode/) { $line=~/\w+\s+.{2}(\w+)\s+\w+\s+.{2}(\w+)/; $return=$1+$2; }# }#close foreach close TEMP; unlink $temp or die "Cannot delete $temp. $!"; ## make sure $return is a valid number. If it is not a number, then set it to 1 to indicate an error condition. ## if $return is NOT defined, then set $return to 1 to raise an error in the calling script. if ( ! defined $return) { $return=1; }#close if # finally we return to the main script and pass the value of $return back to the main script for evaluation. # Doing this will require a modification to the scripts to properly evaluate $return. See template script for # details on doing this. return $return; }