Support Questions
Find answers, ask questions, and share your expertise

how to pass arguments for shellscript in Nifi for ExecuteProcess

Explorer

I have created a Shellscript and It requires three arguments to be passed . It was working fine till I execute it in a terminal . When I configured using Nifi ExecuteProcess ,nifi is ignoring the arguments .

Example :/tmp/script.sh 1 2 8

Refer the attached image . How can I inform nifi to look at the arguments for shell script.

Or kindly advice me to use anyother processor with detailed steps . Since this is not my strongest point .

Thanks!!

71450-ni.png

1 ACCEPTED SOLUTION

Super Guru

@Raj ji

You can use Execute Process (or) Execute Stream Command processors to pass arguments to the shell script.

Execute Process Processor:-

This processor won't need any upstream connections to trigger the script i.e this processor can run its own based on the schedular.

Example:-

I'm having sample script which gets 2 command line arguments and echo output.

bash$ cat sample_script.sh
#!/bin/bash
echo "First arg: $1"
echo "Second arg: $2"

Execution in terminal:-

bash$ ./sample_script.sh hello world
First arg: hello
Second arg: world

1.Execution in NiFi using ExecuteProcess Processor:-

Command

bash

Command Arguments

/tmp/sample_script.sh hello world //here we are triggering the shell script and passing arguments with space 

Batch Duration No value set Redirect Error Stream

false

Argument Delimiter

space //by default

if Argument Delimiter is

;

then command arguments would be

/tmp/sample_script.sh;hello;world


Configs:-

72431-executeprocess.png

Success relation from ExecuteProcess will output the below as content of flowfile

First arg: hello
Second arg: world

2.Execution in NiFi using ExecuteStreamCommand processor:-

This processor needs some upstream connection to trigger the script.

Flow:-

72432-flow.png

We have used generateflowfile processor as a trigger to ExecuteStreamCommand script
Generateflowfile Configs:-

72433-gnf.png

Added two attributes arg1,arg2 to the flowfile

ExecuteStreamCommand processor:-

72434-esc.png

Command Arguments

${arg1};${arg2}

Command Path

/tmp/sample_script.sh

Argument Delimiter

;

Now we are using the attributes that added in generateflowfile processor and passing them to the script.

Use the OutputStream relation from ExecuteStreamCommand processor and the output flowfile content would be same

First arg: hello
Second arg: world

By using these processors you can trigger the shell script and pass the arguments also.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

View solution in original post

1 REPLY 1

Super Guru

@Raj ji

You can use Execute Process (or) Execute Stream Command processors to pass arguments to the shell script.

Execute Process Processor:-

This processor won't need any upstream connections to trigger the script i.e this processor can run its own based on the schedular.

Example:-

I'm having sample script which gets 2 command line arguments and echo output.

bash$ cat sample_script.sh
#!/bin/bash
echo "First arg: $1"
echo "Second arg: $2"

Execution in terminal:-

bash$ ./sample_script.sh hello world
First arg: hello
Second arg: world

1.Execution in NiFi using ExecuteProcess Processor:-

Command

bash

Command Arguments

/tmp/sample_script.sh hello world //here we are triggering the shell script and passing arguments with space 

Batch Duration No value set Redirect Error Stream

false

Argument Delimiter

space //by default

if Argument Delimiter is

;

then command arguments would be

/tmp/sample_script.sh;hello;world


Configs:-

72431-executeprocess.png

Success relation from ExecuteProcess will output the below as content of flowfile

First arg: hello
Second arg: world

2.Execution in NiFi using ExecuteStreamCommand processor:-

This processor needs some upstream connection to trigger the script.

Flow:-

72432-flow.png

We have used generateflowfile processor as a trigger to ExecuteStreamCommand script
Generateflowfile Configs:-

72433-gnf.png

Added two attributes arg1,arg2 to the flowfile

ExecuteStreamCommand processor:-

72434-esc.png

Command Arguments

${arg1};${arg2}

Command Path

/tmp/sample_script.sh

Argument Delimiter

;

Now we are using the attributes that added in generateflowfile processor and passing them to the script.

Use the OutputStream relation from ExecuteStreamCommand processor and the output flowfile content would be same

First arg: hello
Second arg: world

By using these processors you can trigger the shell script and pass the arguments also.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.