Execute shell script in a plugin

clayms
Level 3
Execute shell script in a plugin

Can I execute a shell (bash) script from within a plugin?


Operating system used: centos

0 Kudos
3 Replies
JordanB
Dataiker

Hi @clayms,

Thanks for writing in! Technically, you could execute a shell script in a plugin, however, you cannot convert a Shell recipe into a plugin as you can do with R or Python. Without knowing what your goal is, it's hard to say what your best options might be, but you can execute a shell script in a Python Notebook, convert it to a recipe and then convert the recipe into a plugin (as shown below). If you could describe in detail what you are trying to accomplish, we would be happy to provide you with possible solutions.

Also, I recommend taking a look at our documentation on Plugin Development: https://doc.dataiku.com/dss/latest/plugins/index.html

Screen Shot 2022-08-17 at 4.56.52 PM.png

Best,

Jordan

0 Kudos
clayms
Level 3
Author

Thanks @JordanB 
I did execute a shell script from a python plugin by using the `subprocess` library.  
Now how can I pass in my credentials to the shell script so the shell script has all the same permissions that I have?

It appears that the shell script cannot access some of the resources that the python script has no issue with.

Additionally, when that shell script fires off a separate python file, that python file also does not have the same credentials that I have.  

How can I pass my credentials to a separate python file ?

I do want to do this securely and anytime this plugin runs and any bash or python subprocess that gets executed by the plugin, should be able to adopt the credentials of the person that ran it.  

Thus far, it appears that the only python files that run with my credentials are the plugin's recipe.py file and nothing else.

 

0 Kudos
JordanB
Dataiker

Hi @clayms,

I would suggest trying the python library, Pexpect, which you can find more information on here: https://pexpect.readthedocs.io/en/stable/

You can find examples using Pexpect as well as the subprocess.popen class(used to execute and send data to a child process) here: https://stackoverflow.com/questions/25189348/unable-to-provide-password-to-a-process-with-subprocess...

Please let us know if you have any questions.

Thanks!

Jordan

 

0 Kudos