Clarity

 View Only

Execute bash script from GEL script

  • 1.  Execute bash script from GEL script

    Posted Aug 11, 2015 09:46 AM

    Hi all,

     

    I have a problem with executing .sh script on application server. We are running on RedHat linux.

    Clarity version is: 14.2.0.237

    Java version is: jdk1.7.0_67

     

    The script below works partialy. One part which should create the file execute_export.sh works perfect and the file is created (in my case modified, because it already exists because of permissions). But the second part which should execute the execute_export.sh does nothing. The process with this script finishes without any error.

     

    My objective is to start the execute.jar with parameters. I also tried to execute directly the jar with parameters, but also without any success (see part of code to execute just the jar)

     <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>
        <core:set value="java -jar ${location}/export.jar '${proj_code}' '${period}'" var="myArgs"/>
        <core:invoke method="exec" on="${javaRuntime}" var="execBAT">
            <core:arg type="java.lang.String" value="${myArgs}"/>
        </core:invoke>
        <core:invoke method="waitFor" on="${execBAT}" var="waitBAT"/>
        <gel:log category="XOG" level="INFO">myArgs: ${myArgs}, execBAT: ${execBAT}, javaRuntime: ${javaRuntime},waitBAT: ${waitBAT}</gel:log>
    

     

    Here is my code:

    <gel:script 
        xmlns:core="jelly:core"
        xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:sql="jelly:sql" 
      xmlns:util="jelly:util"
      xmlns:xog="http://www.niku.com/xog"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
      <gel:setDataSource dbId="Niku"/>
        <!-- parametry -->
        <sql:query escapeText="false" var="parametry">
      select 
      par4.c_par_value location
      from odf_ca_c_parameters par4
      where par4.code='jar_location'
      </sql:query>
      <core:forEach items="${parametry.rows}" var="thisRow">
      <core:set value="${thisRow.location}" var="location"/>
      </core:forEach>
      <sql:query escapeText="false" var="jar_params">
      select 
      (select code from inv_investments where id=odf_parent_id) proj_code,
      (select to_char(prstart,'MM-YYYY') from prtimeperiod where prid=c_de_period) period
      from ODF_CA_c_prj_deliv_export where id=${gel_objectInstanceId}
      </sql:query>
      <core:forEach items="${jar_params.rows}" var="thisRow">
      <core:set value="${thisRow.proj_code}" var="proj_code"/>
      <core:set value="${thisRow.period}" var="period"/>
      </core:forEach>
        <!--- Spuštění batch souboru -->
      <file:writeFile delimiter=" " embedded="false" fileName="${location}/execute_export.sh">
        <!-- Print lines to a file-->
        <core:catch var="filerrcreate">
          <file:line>
            <file:column value="echo data >> data.txt"/>
            <!-- 0-->
          </file:line>
       <file:line>
            <file:column value="java -jar ${location}/export.jar '${proj_code}' '${period}'"/>
            <!-- 0-->
          </file:line>
          <gel:out>[XOG]File was created.</gel:out>
          <gel:log category="XOG" level="INFO">File was created.</gel:log>
        </core:catch>
        <core:choose>
          <core:when test="${filerrcreate != null}">
            <gel:out>File creation failed: ${filerrcreate}</gel:out>
            <gel:log category="XOG" level="ERROR">File creation failed: ${filerrcreate}</gel:log>
          </core:when>
          <core:otherwise>
            <gel:out>File was created successfully.</gel:out>
            <gel:log category="XOG" level="INFO">File was created successfully.</gel:log>
          </core:otherwise>
        </core:choose>
      </file:writeFile>
      
      <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>
    
             <core:set value="sh ${location}/execute_export.sh" var="command"/>
    
             <core:invoke method="exec" on="${javaRuntime}" var="execCommand">
                 <core:arg type="java.lang.String" value="${command}"/>
             </core:invoke>
    
    
    </gel:script>
    

     

    Please have you got any idea how to let it work?

     

    Thanks in advance,

    Martin