IBM / xmlservice

XML-based interface for accessing IBM i resources
https://xmlservice.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
35 stars 18 forks source link

Using qsh #6

Closed kadler closed 7 years ago

kadler commented 7 years ago

Original report by Nathanael BONNET (Bitbucket: nbonnet_gaia, GitHub: nathanaelGaia).


Hi,

With version 1.9.8, I tried to use qsh.

It works for a simple commande like ls, but I got an error with /QIBM/ProdData/OS/WebServices/V1/server/bin/listWebServices.sh

#!rpgle
**free
ctl-opt actgrp(*new) ;

dcl-s myXmlIn  char(4096) inz ;
dcl-s myXmlOut char(4096) inz ;

// Doesn't work
myXmlIn =
   '<?xml version="1.0"?><script><qsh rows="on">' +
     '/QIBM/ProdData/OS/WebServices/V1/server/bin/' +
       'listWebServices.sh -server ''ws_test''' +
   '</qsh></script>' ;
exec sql call XMLSERVICE/iPLUG4K('*na','*here',:myXmlIn,:myXmlOut);

// Works fine
myXmlIn =
   '<?xml version="1.0"?><script><qsh rows="on">' +
     'ls' +
   '</qsh></script>' ;
exec sql call XMLSERVICE/iPLUG4K('*na','*here',:myXmlIn,:myXmlOut);

return; 

myXmlOut contains :

#!xml
<?xml version="1.0"?>
<script>
    <qsh rows="on">
        <error>*** error
            /QIBM/ProdData/OS/WebServices/V1/server/bin/listWebServices.sh
            -server 'ws_test'</error>
        <error>202</error>
        <version>XML Toolkit 1.9.8</version>
        <error>
            <status>202</status>
            <errnoxml>1100014</errnoxml>
            <xmlerrmsg><![CDATA[XML run pgm excp]]></xmlerrmsg>
            <xmlhint><![CDATA[xml pase exec]]></xmlhint>
        </error>
        <error>
            <status>202</status>
            <errnoxml>1100014</errnoxml>
            <xmlerrmsg><![CDATA[XML run pgm excp]]></xmlerrmsg>
            <xmlhint><![CDATA[xml pase exec]]></xmlhint>
        </error>
        <jobinfo>
            <jobipc></jobipc>
            <jobipcskey>FFFFFFFF</jobipcskey>
            <jobname>QPADEV000C</jobname>
            <jobuser>QSECOFR</jobuser>
            <jobnbr>158541</jobnbr>
            <jobsts>*ACTIVE</jobsts>
            <curuser>QSECOFR</curuser>
            <ccsid>1147</ccsid>
            <dftccsid>1147</dftccsid>
            <paseccsid>0</paseccsid>
            <langid>FRA</langid>
            <cntryid>FR</cntryid>
            <sbsname>QINTER</sbsname>
            <sbslib>QSYS</sbslib>
            <curlib>NB</curlib>
            <syslibl>QSYS QSYS2 QHLPSYS QUSRSYS</syslibl>
            <usrlibl>OUTILS QGPL QTEMP</usrlibl>
            <jobcpffind>see log scan, not error list</jobcpffind>
        </jobinfo>
    </qsh>
</script>

I tried with using CDATA, several values for IPC and Ctl, qualifing by /usr/bin/sh.

Thanks Nathanaël

kadler commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


fixed

kadler commented 7 years ago

Original comment by Nathanael BONNET (Bitbucket: nbonnet_gaia, GitHub: nathanaelGaia).


Thanks Tony. I have validated some scripts.

kadler commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Ok, added your change. I am assuming you tested to some level.

quotes change

kadler commented 7 years ago

Original comment by Nathanael BONNET (Bitbucket: nbonnet_gaia, GitHub: nathanaelGaia).


Aaron, you're right, my client is a ILE SQL RPG program in this case.

I think the problem comes from any qsh command with a ' (quote).

I modified the source of PLUGILE module, ileExec procedure in order to duplicate all quotes in the command :

#!rpgle
cmdstr = 'STRQSH CMD('''
           + '/usr/bin/qsh -c '''''
           + %scanrpl( '''' : '''''' : %str(cmd:cmdLen))      // + %str(cmd:cmdLen)
           + ''''''')';

then it works !

Aaron, Bill, thanks !

kadler commented 7 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


@starbg, I think his context is different. He's trying to invoke a shell script from XMLSERVICE; which is his client in this scenario.

@nathanaelGaia, take a look at these docs to see how error logging can be turned on.

kadler commented 7 years ago

Original comment by Anonymous.


Nathanaël, I have no official answer here (but just saw your report). The recommendation is generally to use a terminal app on your client computer to execute a shell with SSH. Here's a link to a Ryver discussion (enrollment link here) of the cross-platform one I'm currently using successfully.