Solved

End iSeries Job Programmtically

Posted on 2014-10-27
13
351 Views
Last Modified: 2014-10-30
When I start up a job, two jobs start by default:

QBATCH         QSYS             SBS       .0                                DEQW
      REDIS        QSYSOPR     BCH      .1  PGM-sh                THDW
      REDIS        QSYSOPR     BCI        .1  PGM-redis-serv   SELW

The BCH job is not necessary and I would like to end it programatically.  Does anyone know an easy way to end this job programmatically if I only know the information listed above?

Thanks!
0
Comment
Question by:Matthew Roessner
  • 6
  • 5
  • 2
13 Comments
 
LVL 34

Expert Comment

by:Gary Patterson
Comment Utility
Here's one way:

Create a 28-character data area to hold your job name

CRTDTAARA DTAARA(yourlib/REDISJOB)  TYPE(*CHAR) LEN(28)                      

Open in new window

Add this line to the top of your shell script, before is starts the redis-server.  It will use the PASE getjobid command to get the name of the PASE job and put it into the data area.

system "CHGDTAARA DTAARA(yourlib/REDISJOB *ALL) VALUE('$(getjobid -s $$)')" 

Open in new window


Then you can just use RTVDTAARA and ENDJOB to end the  offending job.
0
 
LVL 1

Author Comment

by:Matthew Roessner
Comment Utility
This is what is in my shell script:

 ************Beginning of data**************                                  
#!/usr/bin/sh                                                                
system "CHGDTAARA DTAARA(NEWDCLIB/REDISJOB *ALL) VALUE('$(getjobid -s $$)')"  


I then start up my program. If I have the system command in there - the program does not execute properly. If I take that out...things work again, so I am thinking maybe my syntax is not quite right or something else is wrong.

Any ideas?

Thanks,
0
 
LVL 34

Expert Comment

by:Gary Patterson
Comment Utility
Runs OK on my system from PASE and from QSH.
What do you mean, exactly when you say "the program does not execute properly"?
Does the data area NEWDCLIB/REDISJOB exist?
Is it *CHAR 28 or greater?
What happens when you run the command manually?  Here's what I get in QSH and PASE:

                                                                                  
  $                                                                               
> getjobid -s $$                                                                  
  807419/TESTUSER/QZSHSH                                                        
  $                                                                               
> system "CHGDTAARA DTAARA(TESTLIB/JOBNAME *ALL) VALUE('$(getjobid -s $$)')"   
  $                                                                               
> system 'dspdtaara testlib/jobname'                                    
  5770SS1 V7R1M0 100423                            Display Data Area     
 1                                                                       
  Data area . . . . . . . . . . . :   DTAARA      JOBNAME                
    Library . . . . . . . . . . . :                 TESTLIB           
  Type  . . . . . . . . . . . . . :   TYPE        *CHAR                  
  Length  . . . . . . . . . . . . :   LEN         28                     
  Text description  . . . . . . . :   TEXT                               
     Offset      Value                                                   
                  *...+....1....+....2....+....3....+....4....+....5     
      0          '807419/TESTUSER/QZSHSH    '                          
                           * * * * *  E N D  O F  L I S T I N G  * * * * 
$                                                                               

Open in new window

0
 
LVL 1

Author Comment

by:Matthew Roessner
Comment Utility
I am able to get the data area to be created in the shell script now. Unfortunately, it is writing the job information for the interactive job that I have running, instead of the job that is started as a part of my process.

So i have my shell script called "startredis".

I do the following to submit the redis job:

SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/redislog/startredis')) JOB(REDIS) JOBQ(QGPL/QREDIS) USER(QSYSOPR)

When I look in the dataarea, it has my Interactive job listed instead of the new job named REDIS like I want...

Thanks for your help!
0
 
LVL 34

Expert Comment

by:Gary Patterson
Comment Utility
Please post your current /redislog/startredis shell script.
0
 
LVL 1

Author Comment

by:Matthew Roessner
Comment Utility
************Beginning of data**************                                                  
 #!/usr/bin/sh                                                                                  
 system "CHGDTAARA DTAARA(NEWDCDATA/REDISJOB *ALL) VALUE('$(getjobid -s $$)')"                  
 CD /QOPENSYS                                                                                  
 /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB
  ************End of Data********************
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:tliotta
Comment Utility
Does everything work correctly after you end the BCH job manually?

Tom
0
 
LVL 1

Author Comment

by:Matthew Roessner
Comment Utility
Yes, after the BCH job is ended manually - everything works completely fine.  I was just wanting to script something to end that job programmatically to keep things clean from a systems perspective and not to confuse our programmers/developers.
0
 
LVL 34

Expert Comment

by:Gary Patterson
Comment Utility
Tested it on my system, and it works file in QP2TERM and QSH, but not when called from QP2SHELL.  Looks like some kind of problem with CCSID conversion or file redirection.  

I'm afraid I just don't have time to troubleshoot it for you - maybe another expert can assist.

I remember when you set this up initially there was some reason you needed to submit it through QP2SHELL, but I can't remember why.  Suspect this would work fine if you could get it kicked off from QSH instead.

Ultimately, that 'extra job' simply doesn't matter that much.  I know it bugs you, but you really can just leave it alone.

Post back if you figure out a solution independently.  I'd like to know the root cause.
0
 
LVL 27

Assisted Solution

by:tliotta
tliotta earned 250 total points
Comment Utility
Looks like some kind of problem with CCSID conversion or file redirection.

File redirection could be related. It's not clear how, though. Note this statement from the QP2SHELL/QP2SHELL2 API documentation:

Neither QP2SHELL nor QP2SHELL2 does the special setup for standard streams that most shells require for reliable operations (stdin, stdout, and stderr must be forkable file descriptors), so these APIs cannot be used without additional programming to run a shell or shell script.

That would almost seem to indicate the opposite.

In general, I would avoid trying to end the BCH job. Even though everything seems to work without it right now, there might be a need for it at any future time. The environment of that job can be used to run functions that cannot be run directly in the PASE environment. E.g., some non-threadsafe function might be run to handle some future exception condition. Or even some normal action that hasn't been invoked yet might make use of it. Until every possible part of the server is executed, it's probably a good idea to let the BCH job continue.

One thing I would do is make sure that the BCH job is fully logging everything that happens in it. A regular check of its joblog might show if/why it might be needed.

Tom
0
 
LVL 1

Author Comment

by:Matthew Roessner
Comment Utility
I don't have to start the job with QP2Shell (at least I don't think so)...how would I submit the job with QSH?  Can I do that from a CL?
0
 
LVL 34

Accepted Solution

by:
Gary Patterson earned 250 total points
Comment Utility
Agree with Tom that likely cause is due to initiation differences between QP2SHELL and QP2TERM/QSH.

I created a shell script that just did the data area update, and when I ran it from QP2TERM and QSH, it ran fine.  When I ran it from QP2SHELL, I got some errors dropped to job logs, including file QINLINE not found, and it didn't update the data area.  Maybe you have to manually handle ENCDIC/ASCII conversion when marshalling data between native and PASE environment in QP2SHELL.  Maybe you need to manually set up file descriptors.  

Lots of ways to do this.  Modify the script to write the getjobid output to a /tmp file, and then grab the job name from the tmp file.  Or use List job API to get a list of jobs and parse it to find the one you are interested in.

Anyway, good news is this is a cosmetic issue, so no harm leaving that initial job out there.   This is normal, expected  behavior for PASE.
0
 
LVL 34

Expert Comment

by:Gary Patterson
Comment Utility
You just use the QSH command instead of CALL QP2SHELL.  Thought from a previous thread that caused you a problem and you had to use QP2SHELL.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now