<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: NIFI execute script issue in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170670#M132968</link>
    <description>&lt;P&gt;Do you mind formatting the code in a "code" block? I see two definitions of copyCommand (you probably wanted to remove the one with all your hostname/port user/pass info)&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 01:03:10 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2017-03-23T01:03:10Z</dc:date>
    <item>
      <title>NIFI execute script issue</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170669#M132967</link>
      <description>&lt;P&gt;I am trying to execute postgres psql command from a  NIFI instance installed on a AWS EC2 instance. I am using the grrovy script.&lt;/P&gt;&lt;P&gt;I have installed the postgresql  utility on EC2 instance using &lt;/P&gt;&lt;P&gt;yum install postgres &lt;/P&gt;&lt;P&gt;Then I execute the command using psql directly from ec2 instance &lt;/P&gt;&lt;P&gt;psql --host=&amp;lt;RDS instance&amp;gt; --port=5432 --dbname=&amp;lt;dbname&amp;gt; --username=&amp;lt;master user&amp;gt; --no-password --command="create database kiran_test_2"&lt;/P&gt;&lt;P&gt;This executes fine.&lt;/P&gt;&lt;P&gt;I try the same on groovy console, it works fine. Please find the code below&lt;/P&gt;&lt;P&gt;import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import groovy.sql.Sql;
def copyCommand = /psql --host=&amp;lt;AWS host&amp;gt; --port=5432 --dbname=&amp;lt;AWS DB&amp;gt; --username=&amp;lt;AWS user&amp;gt; --no-password --command="create database 2"/
def copyCommand = /psql --host=&amp;lt;AWS RDS instance&amp;gt; --port=5432 --dbname=&amp;lt;dbname&amp;gt; --username=&amp;lt;usrname&amp;gt; --no-password --command="create database kiran_test_1"/
        println copyCommand 
        //run psql tool as an external process
        def process = copyCommand.execute()
        def out = new StringBuffer()
        def err = new StringBuffer()
        process.waitForProcessOutput(out, err) //wait for the process to finish
        println "exit code: ${process.exitValue()}"
        if (out.size()) {
            println "Success: $out"
        }
        if (err.size()) {
            println "Error: $err"
        }    &lt;/P&gt;&lt;P&gt;But when I copy the in NIFI script body, it fails complaining "additional attribute database " and fails.&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 22:52:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170669#M132967</guid>
      <dc:creator>krdsranga</dc:creator>
      <dc:date>2017-03-22T22:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: NIFI execute script issue</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170670#M132968</link>
      <description>&lt;P&gt;Do you mind formatting the code in a "code" block? I see two definitions of copyCommand (you probably wanted to remove the one with all your hostname/port user/pass info)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 01:03:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170670#M132968</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-03-23T01:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: NIFI execute script issue</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170671#M132969</link>
      <description>&lt;P&gt;I wonder if the &lt;A target="_blank" href="http://groovy-lang.org/syntax.html#_slashy_string"&gt;slashy string&lt;/A&gt; is causing the problem.  Since you don't have any single quotes in your command, maybe try enclosing the command in single quotes rather than slashes.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 01:05:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170671#M132969</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-03-23T01:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: NIFI execute script issue</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170672#M132970</link>
      <description>&lt;P&gt;Kiran, I believe this has to do with groovy's execute method. I think it is sending the quotes as part of the actual sql to the psql command. Meaning postgres is failing because it doesn't expect the single quotes in a command. Something like the below command would work.&lt;/P&gt;&lt;PRE&gt;import java.sql.DriverManager; 
import java.sql.Connection; 
import java.sql.SQLException; 
import groovy.sql.Sql;

def copyCommand = ['psql', '--host=localhost', '--port=5432', '--dbname=db', '--username=uname', '--no-password', '-c', 'create database kiran_test_0']

println copyCommand //run psql tool as an external process

def process = copyCommand.execute() 
def out = new StringBuffer() 
def err = new StringBuffer()

process.waitForProcessOutput(out, err) //wait for the process to finish 
println "exit code: ${process.exitValue()}"

if (out.size()) { 
println "Success: $out" 
}

if (err.size()) { 
println "Error: $err" 
throw new RuntimeException("$err") 
}
&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 02:08:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NIFI-execute-script-issue/m-p/170672#M132970</guid>
      <dc:creator>jmeyer</dc:creator>
      <dc:date>2017-03-23T02:08:55Z</dc:date>
    </item>
  </channel>
</rss>

