End iSeries Job Programmtically

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!
LVL 1
Matthew RoessnerSenior Systems ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
Please post your current /redislog/startredis shell script.
0
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
************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
tliottaCommented:
Does everything work correctly after you end the BCH job manually?

Tom
0
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
tliottaCommented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gary PattersonVP Technology / Senior Consultant Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.