Invoking q-shell on IBM i-series

Trouble trying to invoke q-shell from remote windows machine using cygwin
gaurav sharmaAsked:
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.

gaurav sharmaAuthor Commented:
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" , 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" 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


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 ?
gaurav sharmaAuthor Commented:
To verify the shell on IBM-i , I logged into IBM-i using the client

2. echo $0    

the output of the above command is

Gary PattersonVP Technology / Senior Consultant Commented:
IBM i ssh server runs in PASE, not QShell.  PASE default shell is bash.

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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

gaurav sharmaAuthor Commented:
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.

Not sure where to go from here.. :-(
Gary PattersonVP Technology / Senior Consultant Commented:
There may be a better way, but this ought to work:

Log into a green-screen sessin and start qshell:


Open in new window

Then execute these commands, replacing your_script_folder with the path to the script you need to run.

echo cd your_script_folder >
echo wsadmin -lang jython -f >>

Open in new window

Then make your new QSH script executable:

chmod 0755

Open in new window

Test the QSH script and make sure it works:

Open in new window

Once you ave it working, start your SSH tunnel, and execute this command
system "QSH CMD('')"

Open in new window

"system" executes an IBM i native command from inside PASE.
QSH is a native command that starts a qshell session, and optionally starts a program or script.
So this should start a QSH session that executes your script, that in turn kicks off your wsadmin script.

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
gaurav sharmaAuthor Commented:
Below are the contents of my script named

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

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/')"

I get the error:

bsh: syntax error at line 1: '(' unexpected
Gary PattersonVP Technology / Senior Consultant Commented:
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.
gaurav sharmaAuthor Commented:
oh ok ..thanks for the explanation.

Ran :

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

Open in new window

output :

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

Open in new window

Gary PattersonVP Technology / Senior Consultant Commented:
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/'\)
gaurav sharmaAuthor Commented:
Removed the double quotes and entered :

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

Output :

bsh: syntax error at line 1: '(' unexpected
Gary PattersonVP Technology / Senior Consultant Commented:
I can't test this at the moment.  Try:

ssh user@gamma system QSH '/path/to/'
gaurav sharmaAuthor Commented:
Ran the above command output:

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

Open in new window

Gary PattersonVP Technology / Senior Consultant Commented:
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/'

Sent to the native command processor.  Some ideas:

ssh user@gamma system QSH ''/path/to/''
ssh user@gamma system QSH \'/path/to/\'
ssh user@gamma system "QSH '/path/to/' "
ssh user@gamma system 'QSH ''/path/to/'' '
gaurav sharmaAuthor Commented:
Thanks a lot ..was finally able to the script using the call like
system "QSH CMD('wsadmin -lang -f /path/to/')"
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
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.