Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

End iSeries Job Programmtically

Posted on 2014-10-27
13
Medium Priority
?
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40406626
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
ID: 40408250
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 35

Expert Comment

by:Gary Patterson
ID: 40408391
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40409071
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 35

Expert Comment

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

Author Comment

by:Matthew Roessner
ID: 40410392
************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
 
LVL 27

Expert Comment

by:tliotta
ID: 40410518
Does everything work correctly after you end the BCH job manually?

Tom
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40410560
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 35

Expert Comment

by:Gary Patterson
ID: 40411615
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 1000 total points
ID: 40412490
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
ID: 40413059
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 35

Accepted Solution

by:
Gary Patterson earned 1000 total points
ID: 40413070
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 35

Expert Comment

by:Gary Patterson
ID: 40413076
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this article, I’ll show how research, determination, and use of modern technology helped me solve a DNA mystery.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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