File path of Shell script

Chris

New member
Dear all,

I have a new phone and net to reconfigure some macros again.

I have a Shell Script which is located in: storage/emulated/0/MacroDroid/filename.sh
I use this combined with the Shell Script action.

But when I use this location in the Shell script action I get the response that the Permission is denied.
However, all permissions are granted for MD and the Helper app.
But then I reminded that with my old phone I needed to use a different syntax/way for writing the file path.
It was something like:
sh /mnt/sdcard/MacroDroid/filename.sh

Maybe the mistake is in this?

I already tried a lot of file paths but as I'm not really an expert, in this, does anyone have any suggestions?

Thanks in advance,

Chris
 

dsnz

Well-known member
did you copy the shell script in new phone ? 😂
if yes, when you use a file manager app what's the path the app shows ?
are you on Android 11 or above ? (then some special permissions are needed per app, you should see a prompt for these with your file manager app, since this is inconvenient to setup I put my scripts in public places like Download)
 

Chris

New member
did you copy the shell script in new phone ? 😂
if yes, when you use a file manager app what's the path the app shows ?
are you on Android 11 or above ? (then some special permissions are needed per app, you should see a prompt for these with your file manager app, since this is inconvenient to setup I put my scripts in public places like Download

Thanks for the reply.
Yes, the scripts are copied :)
I copied the the file path from my file manager to MacroDroid, so that should be okay.
But if I remember well, there was something specific to the way the path should be prompted for a Shell script in MD.
But I forgot what exactly :( I already tried a lot with different paths, but no luck so far...

I made a MD folder in the some folder as the Downloads folder, so it is easily accessible.

I guess it has to do with the way the path is prompted or something....
 

dsnz

Well-known member
when you say "prompted" it makes me think of these new storage frameworks and permissions since Android 11 (and perhaps Android 10 but I skipped this Android version), so all you have to do is to answer this prompt by giving the permission

I can't think of anything else I'm afraid
 

Chris

New member
when you say "prompted" it makes me think of these new storage frameworks and permissions since Android 11 (and perhaps Android 10 but I skipped this Android version), so all you have to do is to answer this prompt by giving the permission

I can't think of anything else I'm afraid
Well, maybe my phrasing was not specific enough. The returned answer is stored in a variable, and that one says that Permission is denied.

I think it has to do with the way the path is build. I checked my old phone again and the path in the file manager is formulated like this:

storage/emulated/0/MacroDroid/filename.sh

But in MD it is mentioned like this:

sh /mnt/sdcard/MacroDroid/filename.sh

So there is some logic behind that I do not know. When I use the same structure of my previous phone, it does not work. So I think I'm doing something wrong.
In that time (previous phone) a former colleague of mine helpt me with this (was a software engineer). But he cannot help me anymore.

I'm on Android 12 btw!

Thanks Chris
 

Jacob L

Moderator (Lawsonator)
The paths are different and need to be the same. Also there's meant to be a leading / so /storage/emulated/0/
not storage/emulated/0/
 

dsnz

Well-known member
if it's not spelling mistake on your part .. the storage/... is indeed wrong as @Jacob L said, there must always be a / in the beginning
 

Chris

New member
Thanks for your input.
The leading / makes no difference by the way. Furthermore I copied and double checked the complete file path.

If I remember well (was 4 years ago} there was something special with how file paths are being written in relation to Shell scripts.
That's als the reason that on my old phone there is an alternative file path as well. But it exceeds my knowledge, and checking the internet did also not clarify things for me :/
 

dsnz

Well-known member
please post
- a screenshot from your file manager showing the script and the file path
- a screenshot of the MD system log or from the MD variable that would receive the script's output that shows the complete full error when trying to execute the script
- a screenshot of the shell action configuration in MD

with good and concrete information a good solution will be found :)
 

RSF

Well-known member
Yes, it's important to understand whether the permission is denied:
  1. To access/run the shell file itself, or
  2. To some command(s) within the shell file
My guess is the problem is #2... If you had the wrong path to the shell file, you'd get a "No such file" error trying to run it vs. a permission error.
But it's possible the shell script is trying to do something that's not allowed in its default execution directory. On my phone MD scripts start in "/", so even a simple "ls" command fails with a permission error -- unless the script first changes to another (readable) directory.
So it'll be helpful to post the info @dsnz mentioned...
 

Chris

New member
Thanks for the help so far.
Below the entered file path and in the popup the response when the Shell Script action is performed.


Screenshot_20220517-192857860.jpg
 

RSF

Well-known member
Try adding "sh" before the path and name of the script, e.g.
sh /storage/emulated/0/Download/plug1aan.sh​
If that doesn't help, try setting the script's "executable" bit (via a one-time shell script) -- although this shouldn't be needed, but it's easy and worth a shot:
chmod +x /storage/emulated/0/Download/plug1aan.sh​
 

Chris

New member
Dear all,

I got things working.

The trick was 1.) Using a freely accessible and existing folder (I use the Downloads folder now). My self-created folder did give issues.

2. Indeed the 'sh' needs to be added to the file path.

With this it works perfectly.
Thanks for all your help!

Regards Chris
 
Top