Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to execute the .sh script on a remote server using NIFI

Highlighted

How to execute the .sh script on a remote server using NIFI

Explorer

I am working on a POC and I have installed the NIFI at my laptop, now i am trying to execute the SH script which hosted on Linux machine, could you guide me on step by steps.

7 REPLIES 7

Re: How to execute the .sh script on a remote server using NIFI

Rising Star

You can use this processor to run the command through `ssh` command to that linux machine, like explained here.

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Explorer

@Marco, thanks for the Answre, But from my local windows machine how i can execute the SSH command. what i am trying to do from my local machine i wanted to execute this command

#!/bin/sh passwrod="Test@Test123" ssh ahmadshe:$passwrod@c4t21128.itcs.hpecorp.net /opt/batchapps/dsas/Jobs/LOAD_ASSURENET_DATA_INTO_DSAS/test.sh

and the test.sh will execute on Linux Remote machine
#!/bin/sh echo "Test Command Execution" >> /opt/batchapps/dsas/Jobs/LOAD_ASSURENET_DATA_INTO_DSAS/text.txt

could you guide me how i can do

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Super Guru

I have a blog post that describes how to use ExecuteScript with Groovy and Sshoogr to execute remote commands via SSH. Not sure if this is what you're looking for but I thought I'd share in case it was useful.

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Explorer

@Matt Thanks for the response. I saw your post and its good. My Requirement is, I have some .SH script which hosted on a Linux machine and i wanted to execute those script using the NIFI.

Issues:NIFI ruining at my laptop and I am trying to get the files from Linux machine how i can achive this ?

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Explorer

Hi Matt, Do you have any template for that ?

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Hi Shakeel,

There is a python package called 'paramiko' that can ssh to a remote linux machine. All you need to do is to write the python script on your local windows machine. Give the hostname and other details to the paramiko object. Then you can use Nifi to run the paramiko.py script on local. This in turn will execute your remote .sh script.

Refer this post for reference: https://stackoverflow.com/questions/3635131/paramikos-sshclient-with-sftp''

Approach 2:

Use the ExecuteStream processor. The inputs are as below:

Command Arguments: user@servername;"bash <yourscript.sh> 2>&1"

Command Path: /usr/bin/ssh

This can execute a remote script if the server/computer is reachable from Nifi cluster. That means that your computer should be ping (able) from the Nifi machines.

If there are better solutions, please share.

Highlighted

Re: How to execute the .sh script on a remote server using NIFI

Explorer

Thanks for the response, do you have template for that ?

Don't have an account?
Coming from Hortonworks? Activate your account here