Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1296  / 3 Years ago, fri, august 27, 2021, 2:25:37

The problem: I'm sharing a directory with my wife. I've placed us both in a 'shared' group and the directory belongs to the 'shared' group as well. Whenever one of us creates a file, this file belongs to user:user, instead of user:shared...



The solution: I can do sudo chown, but my wife can't. So, I want to run a script when I logout of the session.



If I understand correctly, the startup scripts go in /etc/init.d/ and the runlevel scripts go /etc/rc0.d/ where 0 is the runlevel (0-6).



Questions:
Do the runlevel scripts execute only on exit/logout? Do these depend on the user, that is, I'd like to run it only for my user (not so important in this case, mind)? Which runlevel should I choose (my guess is 5)? Should I place the script somewhere else?



Also, I imagine that the script will be run by root, so there's no need for sudo within the script, is that correct?


More From » scripts

 Answers
4

I believe you can use setgid bit?



From man 2 chmod:




S_ISGID (02000) set-group-ID (set process effective group ID
on execve(2); mandatory locking, as described in fcntl(2); take a
new file's group from parent directory, as described in chown(2) and
mkdir(2))




Runlevel scripts are executed only on runlevel changes.



See also this thread: https://superuser.com/questions/65460/create-a-logoff-script-task-for-linux


[#39780] Saturday, August 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nquirewha

Total Points: 256
Total Questions: 109
Total Answers: 122

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;