Solved

End iSeries Job Programmtically

Posted on 2014-10-27
13
451 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
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 34

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 34

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 34

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 250 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 34

Accepted Solution

by:
Gary Patterson earned 250 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 34

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Programmer 26 541
Calling an iSeries system API (QWDRSBSD) from C# 4 480
Coding for returned data using DCL-PR 3 96
IBM MQ moving messages from error queue 4 118
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

823 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