Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 596
  • Last Modified:

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!
0
Matthew Roessner
Asked:
Matthew Roessner
  • 6
  • 5
  • 2
2 Solutions
 
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 RoessnerAuthor 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Matthew RoessnerAuthor 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 RoessnerAuthor 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 RoessnerAuthor 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 RoessnerAuthor 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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now