Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Invoking q-shell on IBM i-series

Trouble trying to invoke q-shell from remote windows machine using cygwin
0
gaurav sharma
Asked:
gaurav sharma
  • 8
  • 6
1 Solution
 
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 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 ?
0
 
gaurav sharmaAuthor 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
0
 
Gary PattersonVP Technology / Senior Consultant 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
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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.


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.. :-(
0
 
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:

QSH

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 > runtestpy.sh
echo wsadmin -lang jython -f test.py >> runtestpy.sh

Open in new window

Then make your new QSH script executable:

chmod 0755 runtestpy.sh

Open in new window

Test the QSH script and make sure it works:

runtestpy.sh

Open in new window

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

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.
0
 
gaurav sharmaAuthor 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
0
 
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.
0
 
gaurav sharmaAuthor 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

0
 
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/test.sh'\)
0
 
gaurav sharmaAuthor 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
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
I can't test this at the moment.  Try:

ssh user@gamma system QSH '/path/to/test.sh'
0
 
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

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

Featured Post

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!

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