Tip

Periodically run a job -- manually

Do you need to have a job run periodically but don't want to have to deal with manually starting it every time? I wrote a monitor to check, and warn me if certain jobs weren't running. I needed this "health monitor" to run every fifteen minutes but I did not want to have it sitting in QBATCH with a DLYJOB. Instead I submitted it as a scheduled job and then after it checks the jobs, it adds fifteen minutes to whatever time it is and submits itself as a scheduled job. With this code (and it could probably be cleaned up some), one could take any periodic job and have it run itself.


  
 *****************************************************                         
 * Submit the scheduled job                                                    
 *****************************************************                         
                                                                               
C     submitagain   begsr                                                      
                                                                               
 * First see if the health monitor is running                                  
C                   clear                   command                            
C                   eval      command = 'OVRPRTF FILE(QSYSPRT) HOLD(*YES) '    
C                             + 'OVRSCOPE(*JOB)'                               
C                   callp(e)  execcommand(command:length)                      
                                                                               
C                   clear                   command                            
C                   eval      command = 'WRKJOBSCDE JOB(XCHCOM'                
C                                    + %trim(invendid) + ') OUTPUT(*PRINT)'    
C                   callp(e)  execcommand(command:length)                      
                                                                               
C                   clear                   command                            
C                   eval      command = 'CPYF FROMFILE(JHAXCI/XCSPLF) '        
C                                     + 'TOFILE(QTEMP/XCSPLF) '                
C                                     + 'MBROPT(*REPLACE) '                    
C                                     + 'CRTFILE(*YES)'                        
C                   callp(e)  execcommand(command:length)                
                                                                         
C                   clear                   command                      
C                   eval      command = 'CPYSPLF FILE(QSYSPRT) '         
C                                     + 'TOFILE(QTEMP/XCSPLF) '          
C                                     + 'SPLNBR(*LAST) '                 
C                                     + 'MBROPT(*REPLACE)'               
C                   callp(e)  execcommand(command:length)                
                                                                         
C                   callp     dltovr('QSYSPRT')                          
                                                                         
C                   clear                   command                      
C                   eval      command = 'DLTSPLF FILE(QSYSPRT) '         
C                                     + 'SPLNBR(*LAST)'                  
C                   callp(e)  execcommand(command:length)                
                                                                         
C                   callp     ovrdbfqtemp('XCSPLF')                      
C                   open      xcsplf                                     
C                   do        5                                          
C                   read      rxcsplf                                99  
C                   enddo                                                
C                   close     xcsplf                                     
C                   callp     dltovr('XCSPLF')                           
                                                                          
 * If health monitor is running then end this madness                     
C                   if        %subst(splfdata:2:10) = 'XCHCOM' + invendid 
C                   goto      endpgm                                      
C                   endif                                                 
                                                                          
C                   time                    ztime                         
C                   adddur    15:*minutes   ztime                         
C                   extrct    ztime:*m      zmm                           
C                   extrct    ztime:*d      zdd                           
C                   extrct    ztime:*y      zyyyy                         
C                   move      zyyyy         zyy                           
C                   extrct    ztime:*h      zhh                           
C                   extrct    ztime:*mn     zmn                           
C                   extrct    ztime:*s      zss                           
                                                                          
C                   clear                   command                       
                                                                          
C                   eval      command = 'ADDJOBSCDE JOB(XCHCOM'           
C                             + %trim(invendid)                           
C                             +  ') CMD(CALL PGM(JHAXCI/XCHCOM) '         
C                             +  'PARM(''*Next'' ''' + %trim(invendid)    
C                             +  ''')) FRQ(*ONCE) '                       
C                             +  'SCDDATE(' + zmm + zdd + zyy + ') '      
C                             +  'SCDTIME(' + zhh + zmn + zss + ') '
C                             +  'MSGQ(*NONE) '                     
C                             +  'TEXT(''JHAXCI Health Monitor'')'  
                                                                    
C                   callp(e)  execcommand(command:length)           
                                                                    
C                   endsr      
  
  

This was first published in May 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.