A fix on CPAN module MVS::JESFTP

Last week, I tried to do some work through MVS::JESFTP.  Actually, I knew this module for a long time,  just had  an idea to automate the process of submitting JCL job and fetching joblog, so I decided to reuse the module rather than invent a new wheel.  However, firstly I met problem on invoking function wait_for_results while trying out it.  I searched related info online, although some similar questions posted,  still could't find any clue to solve them. No way except dirty my hands.  Source code of   wait_for_results is as below.


 
 
sub wait_for_results { #------------------------------------------------
my ( $self , $JOB , $TIMEOUT ) = @_ ;

$JOB =~ s/\..+$// ;
$TIMEOUT ||= 60 ;

my @results = ();
my $i = 0 ;
while ( ++ $i <= $TIMEOUT ) {
# print "$i: waiting for $JOB...\n";
last if ( @results = grep /^$JOB\s+JOB\d+\s+OUTPUT/ , $self -> dir );  
sleep ( 1 );
}
return ( @results ) ? \ @results : undef ;
} #---------------------------------------------------------------------

By investigating the code, found that culprit is regexp for grep "^$JOB\s+JOB\d+\s+OUTPUT" .  It looks like good, unfortunately, it can't work on my system which issues following job info. 

         JOBFTP   JOB00254 THINKHY OUTPUT A        RC=0256 4 spool files


The third segment is username but not  OUTPUT as the regexp shows.  What I need to do next is very simple,  to relax the match condition and fix a line as below.

         Before:  

lastif(@results=grep/^$JOB\s+JOB\d+\s+OUTPUT/,$self->dir);

         After:      

lastif(@results=grep/^$JOB\s+JOB\d+/i,$self->dir);          


In addition, to ensure the code can work in various environment, add two lines to specify jesstatus and jesjobname.

 
 
$self -> quot ( 'SITE' , 'jesstatus=all' ) or return undef ;
$self -> quot ( 'SITE' , "jesjobname=$JOB" ) or return undef ;


Now,  the code of wait_for_results is 

   

 
 
sub wait_for_results { #------------------------------------------------
my ( $self , $JOB , $TIMEOUT ) = @_ ;
    
$JOB =~ s/\..+$// ;
$TIMEOUT ||= 60 ;

my @results = ();

$self -> quot ( 'SITE' , 'jesstatus=all' ) or return undef ;
$self -> quot ( 'SITE' , "jesjobname=$JOB" ) or return undef ;

my $i = 0 ;
while ( ++ $i <= $TIMEOUT ) {
# print "$i: waiting for $JOB...\n";
         #last if (@results = grep /^$JOB\s+JOB\d+.*?\s+OUTPUT/, $self->dir);

         # Fix the regexp, relax the match condition. [6/9/2012 thinkhy]
last if ( @results = grep /^$JOB\s+JOB\d+/i , $self -> dir );

sleep ( 1 );
}

return ( @results ) ? \ @results : undef ;

} #---------------------------------------------------------------------


Finally this CPAN works perfectly on my system. Anyway, it is truly appreciated that Mike Owens implemented the useful module for us.  Hope my work is also helpful for you. Please contact me(think.hy@gmail.com)  freely if any feedback.


Reference

       1  Submit batch jobs from Java on z/OS

            http://www.ibm.com/developerworks/systems/library/es-batch-zos.html


       2 Access z/OS batch jobs from Java 
            http://www.ibm.com/developerworks/systems/library/es-zosbatchjavav/index.html



6/11/2012 Update

   

 In the regular expression lastif(@results=grep/^$JOB\s+JOB\d+/i,$self->dir);  ,  I  missed the OUTPUT segment that would lead to error for retrieval of  data stream when job is in active state.  Modified the regular expression as following.

        @results=grep/^$JOB\s+JOB\d+.*?OUTPUT/i,@tmp_results;


     Another thing is about multiple jobs with the same job name, I think only If all these jobs are finished(in OUTPUT state) , we can download joblogs.   So I added some code in function wait_for_results to ensure job logs can be downloaded in a correct way.

 
 
sub wait_for_results { #------------------------------------------------
my($self, $JOB, $TIMEOUT) = @_;
    
$JOB =~ s/\..+$//;
$TIMEOUT ||= 60 * 60 * 24; # Default timeout value

my @results = ();

$self->quot('SITE', 'jesstatus=all') or return undef;
$self->quot('SITE', "jesjobname=$JOB") or return undef;

my $i = 0;
while (++$i <= $TIMEOUT) {
print "$i: waiting for $JOB...\n";

        # Fix the regexp, relax the match condition. [6/9/2012 thinkhy]
        my @tmp_results = $self->dir;

        shift @tmp_results; # Remove title row
        #print join "\n", @tmp_results;

        next unless(@tmp_results); # If job log is unavaliable.

        @results = grep /^$JOB\s+JOB\d+.*?OUTPUT/i, @tmp_results;

        # If all the jobs are in OUTPUT state , that way we can download joblog.
        last if ($#tmp_results == $#results);

sleep(1);
}

return (@results) ? \@results : undef;

} #---------------------------------------------------------------------


 Complete code of my jesftp.pm has pasted to github: https://gist.github.com/2900792



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值