"Permission Denied" error in Execute a Shell Script

Do I have to mark a shell script file as executable in order to use it from the "Execute a Shell Script" action?

If so, is there a KM Action that can do this? If not, do I have to use sudo to execute chmod?

I'd like to do this from a KM macro which I'd like to share with people. Is it possible?

Thanks.

You might want to consider creating an "Execute Shell Script" action programmatically in a macro, and then execute it. The reason for this is that you don't need to set any permissions when the script itself is inside a KM action.

That's an interesting solution. Under any other circumstances, I would do it just like that.

One of these days I'll be able to explain, but not right now. :slight_smile:

1 Like

You can use an Execute Shell Script action which contains the following: (where you use the full path of your file.)

chmod 777 /Users/myname/data/x.sh

The number 777 makes it so that Owner, Group and World all have read/write/execute action. You might want to narrow that down to the minimum permissions required.

1 Like

Yes. But depending on the script you can execute the interpreter explicitly.

For example:

/Path/to/test.pl

will fail with Permission Denied, but

perl /Path/to/test.pl

will work fine.

Otherwise you can add the executable bit, which generally does not require any more permission than being able to write the file.

chmod u+x ~/perl/test.pl
~/perl/test.pl
2 Likes

You could even do it all in the macro you share:

Script Demo.kmmacros (3.0 KB)

2 Likes

Thank you - that's exactly what I needed to know!