Solved

Start QSH command from CL

Posted on 2014-09-10
19
1,005 Views
Last Modified: 2014-09-19
I am attempting to start Redis from a CL program.  Typically, this is the process I use to start Redis:

CALL QP2TERM
CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

I want to do this from a CL instead of manually through command line.  Does anyone know how I can accomplish this?

Any help is much appreciated.
0
Comment
Question by:Matthew Roessner
  • 10
  • 9
19 Comments
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40315341
Use qp2shell:

http://forums.iprodeveloper.com/forums/aft/49452

Create a little shell script that does this:

CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

Then run  that script by calling qp2shell.
- Gary
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40315384
I don't have any experience with creating shell scripts.

I just created something in the /redislog directory. I just did a

EDTF '/redislog/startredis'

Then I pasted in the two commands:

CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

I saved that...and then created a CL with the following:

 CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

This didn't work...  Got the following:

Error loading i5/OS PASE program /redislog/startredis
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40315537
New files aren't created with execute authority.

Go into PASE,

chmod 0755 /redislog/startredis

To make the script executable, and try it again.
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40316680
I did the following:

CALL QP2TERM

$ chmod 0755 /redislog/startredis

After doing this, I re-ran it and I again got the following:

i5/OS PASE program or shell script not executable. Path is /redislog/startredis.                                              
Error loading i5/OS PASE program /redislog/startredis.  See previous messages.
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40317214
To call from qp2shell, you need this as the top line of your script:

#!/usr/bin/sh

Also make sure the script file is in ASCII (CCSID 819 on my US-localized machine), and uses LF as the new line terminator.  This is one way to do it from a QP2TERM:

echo \#!/usr/bin/sh > /redislog/startredis
echo CD /QOPENSYS >> /redislog/startredis
echo /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB >> /redislog/startredis

chmod 0755 /redislog/startredis

Open in new window

0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40317649
I think we are almost there. I am able to start Redis now from my program...but the program never "completes".  Is there any way to "exit" the Qshell?

If I simply call my program:  CALL LIBRARY/REDISSTR - I get an X on my screen and control is never returned.  I see the following in my QBATCH sbs:

STARTREDIS   QSYSOPR     BCH      .0  PGM-sh           THDW
STARTREDIS   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

Basically it looks like the top job (the PGM-sh) has control.  Essentially the same thing happens if I do a SBMJOB.  

Any idea how to get that part to end - but to keep the bottom job running?

I really appreciate all the help!

Matt
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40317791
Try putting the "source" command or "exec" command in front of the redis-server command:

source /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

or

exec /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

"source" says to run the program/script in the current shell instead of spawning a new one.  If the redis-server program ends eventually, the next line of your startredis script would then run, if there was one.

"exec" says to run the program.script IN PLACE OF the current shell.  So control gets transferred to redis-server.  When it ends the shell will end, and if there were more lines in the startredis script they would never be executed.
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40317831
I attempted to use both EXEC and SOURCE.  When I used either of these and ran my program:

CALL <LIBRARY>/REDISSTR


Nothing happens...  The Redis job does not start (but control is returned...)  Essentially it looks like the command runs but it doesn't do anything
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40317887
Just to clarify, this is not qshell.  

It is PASE, which defaults to the bash shell.  QP2TERM and QP2SHELL start the PASE environment.  QSH command starts the qshell environment.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40317900
OK, so I assume you have a CL called REDISSTR.

In it you have the CALL QP2SHELL command.  When you use the script with a direct invocation of redis-server, the job with your CL running in it hangs waiting for the CALL to complete (which it won't because redis-server is a server that is supposed to start and stay running).

And when you try to use source or exec, the redis-server doesn't appear to start properly.

Why not just submit the CALL QP2SHELL command to batch instead of calling it from a CL?  Does that do what you want?
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333003
Sorry I have been out of the office this week.

When I just run the CALL QP2SHELL command:

CALL PGM(QP2SHELL) PARM('/redislog/startredis')

I get the following message from within the QSH screen:

/redislog/startredis[3]: /QOpensys/opt/freeware/sbin/redis-server --logfile /
redislog/redis-server.log --maxmemory 1GB:  not found.                      
Press ENTER to end terminal session.                                        

Then I have to press enter to return to the command line. The Redis server does not start...

I appreciate all your help thus far...
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333030
I apologize for the previous post. I still had the EXEC command inside of my startredis shell script.

I can not call the:

CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

from a command line, but it essentially freezes the screen (with a X in the window) and stays active. It shows the following jobs running:

REDIS_TEST   QSYSOPR     BCH      .0  PGM-sh           THDW
REDIS_TEST   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

The top job should not be running, but the bottom job should.  I attempted to start this via a SBMJOB command, but I get the same thing (minus the hung session).

Any ideas?
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40333118
That looks right to me.  redis-server is a server-style job / a daemon / a never-ending program, and you're having trouble getting it to run in the initial shell - so let it spawn its own thread and run.  Normally you'd submit this to batch or set it up as an auto-start job.  

Is the only problem that you just don't like the look of the BCH job hanging there?  If so, just start it form batch.  you generally start a server job like this from a job scheduler or from an autostart job anyway.  The "hanging" initial shell is functioning perfectly - it is just waiting for redis-server to end, and it will terminate when it does.
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333181
When you say "Submit to batch" - do you mean from a iSeries command line?

When I do this - it freezes my screen that I submit from.

From the command line, I call the following:

CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

This freezes my screen...
0
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 40333275
You use the SBMJOB command to submit a batch job.  Specific parameters to run in your environment are going to vary.  Do you have a sysadmin who can help you?
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333326
I did try submitting the job via the SBMJOB command:

SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/redislog/startredistest')) JOB(REDIS_TEST) JOBQ(*LIBL/QREDIS) USER(QSYSOPR)  

When I do it this way - 2 jobs start - like I said above:

REDIS_TEST   QSYSOPR     BCH      .0  PGM-sh           THDW
REDIS_TEST   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

Control is returned to the screen this way - I would just rather not have the BCH job running...
0
 
LVL 34

Accepted Solution

by:
Gary Patterson earned 500 total points
ID: 40333437
Yes.  Based on what you are doing, that is how it should look.  I bash when a script calls another script like this a new shell is spawned.  The way to stop that behavior is by using source or exec and you said that didn't work when you use qp2shell.  That isn't a surprise.

I understand that you don't like the way it looks, but this is how this is supposed to work based on what you are doing.  

- Gary
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333439
Thanks for all your help
0
 
LVL 1

Author Closing Comment

by:Matthew Roessner
ID: 40333442
Very helpful
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RPG IV and RPG ILE book 4 411
Access Remote iSeries IFS 6 285
Issue Copying Tables/Files from one iSeries to Another 19 82
IBM 840 flash storage Array 3 158
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

19 Experts available now in Live!

Get 1:1 Help Now