We help IT Professionals succeed at work.

Invoking q-shell on IBM i-series

666 Views
Last Modified: 2014-09-18
Trouble trying to invoke q-shell from remote windows machine using cygwin
Comment
Watch Question

Author

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 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 ?

Author

Commented:
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
Gary Patterson, CISSPExpert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT

Commented:
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

Author

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.


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.. :-(
Expert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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
Gary Patterson, CISSPExpert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT

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.

Author

Commented:
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

Gary Patterson, CISSPExpert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT

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/test.sh'\)

Author

Commented:
Removed the double quotes and entered :

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

Output :

bsh: syntax error at line 1: '(' unexpected
Gary Patterson, CISSPExpert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT

Commented:
I can't test this at the moment.  Try:

ssh user@gamma system QSH '/path/to/test.sh'

Author

Commented:
Ran the above command output:

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

Open in new window

Gary Patterson, CISSPExpert for hire: IBM i, AIX, Linux, Windows, DB2, Performance, Security. EDI
CERTIFIED EXPERT

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

Author

Commented:
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')"

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.