Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a weird problem with strip command of binutils package.
When I run this command from a shell script, I get a permission denied error.
Instead, if I run the same command for the same user from a terminal session, it works!
Moreover, I always used this script and it always worked but
I don't understand the reason for which it fails on these resources.
Any advice?
It might help for us to see the script, at least the strip bit and surrounding lines.
The command is :
Code:
strip --strip-all "$res"
I didn't posted other code because is useless.
Anyway, I tried to run that script as root ad it worked.
Why? I don't understand the reason.
Basically, I download a tar archive from internet, extract it into a folder and
strip the executables and shared objects.
This script always worked, just for this archive it fails with permission denied error.
I tried to inspect the previous tar archives than this one,
I also saw that for those archive the owner and group are set to root, hence, that seem useless (theorically).
Why does it not work in this case as normal user ?
The most obvious answer is: because the user has no right to write that file. strip tries to modify a file, so it requires both read and write permission.
Check them.
Does your script extract to /tmp or /var/tmp?
The Linux kernel behavior changed, now root is restricted in directories with a t-bit. https://www.claudiokuenzler.com/blog...-tmp-even-root
You can change it back to the Unix standard:
Code:
echo 0 > /proc/sys/fs/protected_regular
or
Code:
sysctl fs.protected_regular=0
Last edited by MadeInGermany; 03-11-2024 at 03:23 PM.
The most obvious answer is: because the user has no right to write that file. strip tries to modify a file, so it requires both read and write permission.
Check them.
I am fully agree with you but like I wrote above,
if I run the same command for the same user in a terminal session, it works.
The problem only exist when it is executed from shell script
and that's very weird.
Does your script extract to /tmp or /var/tmp?
The Linux kernel behavior changed, now root is restricted in directories with a t-bit. https://www.claudiokuenzler.com/blog...-tmp-even-root
You can change it back to the Unix standard:
Code:
echo 0 > /proc/sys/fs/protected_regular
or
Code:
sysctl fs.protected_regular=0
Actually, my script is not extract but the files are extracted which will be stripped instead.
fs.protected_regular is already set to zero.
I am fully agree with you but like I wrote above,
if I run the same command for the same user in a terminal session, it works.
The problem only exist when it is executed from shell script
and that's very weird.
I just added "chmod u+w $res" before strip execution and it worked but, anyway
that's is weird because:
1) The resource has already write permission.
2) If I run the same command for the same user into terminal session, it works.
Likely, when the files are extracted from tar archive, inherit the fake permissions....
Just a thought.
Likely, when the files are extracted from tar archive, inherit the fake permissions....
tar itself restores the original permissions, at least it tries. You need to read the man page for details, it may work differently for users and root.
tar itself restores the original permissions, at least it tries. You need to read the man page for details, it may work differently for users and root.
I agree again, but if I extract tar archive and see that the permissions are correct (read, write and execution in my case) for the current user then expect it works, regardless man page reading.
When I run "chmod u+w", on the file system nothing changes occurs but i have to do that otherwise doesn't work.
According tar man page:
Code:
--no-same-owner
Extract files as yourself (default for ordinary users).
--no-same-permissions
Apply the user's umask when extracting permissions from
the archive (default for ordinary users).
The umask for my user is 0022 which is 0644 like permissions.
It should works without any changes but it doesn't....
I agree again, but if I extract tar archive and see that the permissions are correct (read, write and execution in my case) for the current user then expect it works, regardless man page reading.
When I run "chmod u+w", on the file system nothing changes occurs but i have to do that otherwise doesn't work.
According tar man page:
Code:
--no-same-owner
Extract files as yourself (default for ordinary users).
--no-same-permissions
Apply the user's umask when extracting permissions from
the archive (default for ordinary users).
The umask for my user is 0022 which is 0644 like permissions.
It should works without any changes but it doesn't....
If it is true you did not tell us the full story. If it is a remote drive, if several hosts are involved, if <whatever>... which was not explained.
Otherwise would be nice to see the exact commands, the exact result and obviously the real environment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.