Reputation: 377
I have a large wrapper.sh
file which does a lot of things, but in the end runs catalina.sh
tomcat.
Problem is that users who run this wrapper.sh
are experiencing error: no permissions to execute catalina.sh
. They have to manually set this permission, which is something I do not want.
On my computer, chmod u+x catalina.sh
fixes this, therefore I included it in the wrapper.sh
, right before executing catalina.sh
:
#!/bin/sh
# <...>
# <...>
chmod +x catalina.sh
exec ./catalina.sh
But will this change work for everyone? I can imagine, for example, that it indeed works fine on my computer, but someone else would get some sudo-related error when implicitly running that chmod
. How can I make it work for everyone?
Upvotes: 0
Views: 2022
Reputation: 58578
It will work if the user is root, or else the owner of catalina.sh
.
An unprivileged user cannot change the permissions on a file that the user does not own, even if it is writable.
If catalina.sh
is something that the same user unpacked, or that your script created, there shouldn't be a problem.
The one issue might be that the user is trying to do this in a filesystem that is mounted noexec
. But then the wrapper.sh
script itself wouldn't be executable. Yet, the user could successfully run sh wrapper.sh
in spite of it not being executable, and then run into the catalina.sh
problem.
Note that you can exec sh ./catalina.sh
. Just because the script not executable doesn't mean you cannot exec a new process image for the interpreter to process it; you just have to do it explicitly rather than relying on the operating system to bind the interpreter to the script. That is what requires execute permissions.
Upvotes: 2
Reputation: 22225
How about running it instead by sh catalina.sh
or bash catalina.sh
(depending on what language that script is written in)? In this case, you don't need x-permission. Read permission is enough.
Upvotes: 4
Reputation: 9
Upvotes: 0