cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Run stored bash in Databricks with %sh

keunsoop
New Contributor

Hi, I made bash file in databricks and I can see that the file is stored as the following picture.

0693f000007OoILAA0

I was supposed to run this bash file through %sh cell, but as you see the following picture, I could not find bash file, which I could find through dbutils.fs.

Is there any way to run bash file stored in dbutils through the cell? This bash file is for installing packages, and executed as restarting cluster, but I would like to run this one manually so that I do not need to restart cluster whenever package is updated. Thanks.

0693f000007OoIMAA0

1 ACCEPTED SOLUTION

Accepted Solutions

jose_gonzalez
Moderator
Moderator

Hi @keunsoop​ ,

Are you able to run your code using an init script? I would like to share some docs in case you might have some questions https://docs.databricks.com/clusters/init-scripts.html

View solution in original post

8 REPLIES 8

User16857282152
Contributor

The %sh command runs on the driver,

The driver has dbfs: mounted under /dbfs

So paths you might think of as dbfs:/FileStore end up being /dbfs/FileStore

I was able to execute a shell script by uploading to the FileStore

Moving to current working directory with a

%sh mv command

and then executing with a

%sh sh myscript.sh

@Tom Hanlon​  Uploading to FileStore path is to create data. How can we easily access the directory and upload .sh file to run the same in the workspace?

Lokesh_Vish
New Contributor II

Hello @Tom Hanlon​ 

Could you please explain in details how it is done,

I am not able to run the .sh file in databricks

jimnaik
New Contributor III

@Lokesh_Vish​ were you able to execute it?

I am facing similar issue and not able to upload and execute .sh as well as .py file.

Anonymous
Not applicable

Hello @Jimit Naik​ - My name is Piper, and I'm a Databricks community moderator. Thank you for asking about this. We'll give the community a chance to respond first. 🙂

Kaniz
Community Manager
Community Manager

Hi @keunsoop​ , @Lokeshkumar Madabathula​ and @Jimit Naik​ , Please try this after uploading it to the 'Data' section of the workspace:-

%sh /dbfs/***/***/***.sh

Atanu
Esteemed Contributor
Esteemed Contributor

this can be run through init script I think,@keunsoop​ 

jose_gonzalez
Moderator
Moderator

Hi @keunsoop​ ,

Are you able to run your code using an init script? I would like to share some docs in case you might have some questions https://docs.databricks.com/clusters/init-scripts.html

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.