Link to home
Start Free TrialLog in
Avatar of gaurav sharma
gaurav sharma

asked on

Invoking q-shell on IBM i-series

Trouble trying to invoke q-shell from remote windows machine using cygwin
Avatar of gaurav sharma
gaurav sharma

ASKER

I have a IBM-i series machine where websphere is installed.
I have created jython script to automate the websphere war deployment and placed it in a directory on IBM-i.
Below are the steps to invoke the script through I-series client.(green screen)

Log in to IBM-i using the client and enter STRQSH
The above command will start the Q-Shell and then
I navigate to the directory where I copied the jython script and run it as "wsadmin -lang jython -f test.py" , which installs the war on webpshere


=======================================================

I am trying to invoke the same jython script on IBM-i from another windows server which has cygwin installed.
I created a ssh tunnel from the remote windows machine to IBM-i and I am able to login to IBM-i machine from the windows machine using the SSH tunnel by using the below command

ssh user1@ibm-i       ====>logs me into the IBM-i machine without any password


I navigate to the directory where the jython script is present and invoke the script as "wsadmin -lang jython -f test.py" and I get the below error


wsadmin: syntax error at line 12: '(' unexcepted.


I entered command

echo $0   ===(to see which shell I was using after I logged into IBM-i through cygwin) and the output is

-bsh

Its showing Bash instead of Q-shell.

==========================================================
Is there a profile setting that I am missing here on I-series that would intialize the Q-shell

when I login from cygwin ?
To verify the shell on IBM-i , I logged into IBM-i using the client

1. STRQSH
2. echo $0    

the output of the above command is

QSHELL/QZSHSH
Avatar of Gary Patterson, CISSP
IBM i ssh server runs in PASE, not QShell.  PASE default shell is bash.  

http://www.mcpressonline.com/tips-techniques/programming/techtip-qshell-vs-pase.html

Since jython is interpreted, you probably just have a CCSID issue.  Compare the PASE CCSID and the script file CCSID and make sure they match.  It is a good idea to store scripts that will run in PASE in the QOpenSys file system.

- Gary
I am newbie to IBM-i. Thanks for the clarification. Checked the IBM Websphere site and the wsadmin utility I am trying to invoke only works in Q-shell. Below are the steps to start the utility in mentioned in the site

Steps for this task

    From the OS/400 command line, start a Qshell session by issuing the STRQSH CL command.
    Change to the bin directory.
    Run the command.


http://www-01.ibm.com/support/knowledgecenter/SSAW57_7.0.0/com.ibm.websphere.nd.doc/info/ae/ae/rxml_commandline.html?cp=SSAW57_7.0.0%2F1-16-1-71


Not sure where to go from here.. :-(
ASKER CERTIFIED SOLUTION
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Below are the contents of my script named test.sh

cd /QIBM/ProdData/Websphere/Appserver/V7/ND/bin/
wsadmin -lang jython -f /Prod/was_scripts/start.py

Gave the script 777 permissions

I started QSH through the green screen and ran the script by getting to the path and it worked fine.

Through ssh tunnel:

ssh user@gamma "QSH CMD('/Prod/was_scripts/test.sh')"
 

I get the error:

bsh: syntax error at line 1: '(' unexpected
QSH is a native IBM i OS command, not a PASE program or script.  You can only execute PASE programs and scripts from ssh - at least directly.

You need to run the "system" command, which takes QSH command as a parameter, just like my example above.

It is a maze of twisty little passages:

ssh - Starts a PASE shell
system - PASE command that executes a native IBM i OS command from PASE
QSH - IBM i OS command that starts qshell environment.

Maybe there is a way to start QSH directly from PASE, but I've never needed to do it.  This should at least get the job done.
oh ok ..thanks for the explanation.

Ran :

ssh user@gamma system "QSH CMD('/path/to/test.sh')"

Open in new window


output :

bsh: syntax error at line 1: '(' unexpected

Open in new window

Some characters have a special meaning to bash.  When that happens, escape the problem character with a backslash.  

ssh user@gamma system QSH CMD\('/path/to/test.sh'\)
Removed the double quotes and entered :

ssh user@gamma system QSH CMD\('/path/to/test.sh'\)

Output :

bsh: syntax error at line 1: '(' unexpected
I can't test this at the moment.  Try:

ssh user@gamma system QSH '/path/to/test.sh'
Ran the above command output:

CPD0049: Qualified name not valid for parameter CMD
CPF0006: Errors occured in command

Open in new window

Looks like the single quotes are getting stripped before they make it to the native command processor.  

Try doubling, escaping, quoting, etc:  Your goal is to get the command

QSH '/path/to/test.sh'

Sent to the native command processor.  Some ideas:

ssh user@gamma system QSH ''/path/to/test.sh''
ssh user@gamma system QSH \'/path/to/test.sh\'
ssh user@gamma system "QSH '/path/to/test.sh' "
ssh user@gamma system 'QSH ''/path/to/test.sh'' '
Thanks a lot ..was finally able to the script using the call like
#!/usr/bin/qsh
system "QSH CMD('wsadmin -lang -f /path/to/script.py')"