Operating System - HP-UX
1833247 Members
2969 Online
110051 Solutions
New Discussion

Shell scripting and changing group id

 
SOLVED
Go to solution
Belinda Dermody
Super Advisor

Shell scripting and changing group id

HP-UX 10.20. Is there a way you can change a user to a new group without starting up a new shell ( like newgrp command) within a script. I have a certain security group that writes files to to a directory owned by root and group is a/r the permission are 770 on the directory. People belong to different primary and a/r is secondary, but the system wont let them cd to the directory. I can do it with sudo commands, but I would rather not use it.
7 REPLIES 7
Santosh Nair_1
Honored Contributor
Solution

Re: Shell scripting and changing group id

Have you tried setting up the /etc/logingroup file. This should fix the problem of the user not being able to cd into the directory. As long as they are a member of the group that owns the directory and the directory has execute permissions, the user should be able to cd in to the directory.

Just link /etc/group /etc/logingroup.

-Santosh
Life is what's happening while you're busy making other plans
James Beamish-White
Trusted Contributor

Re: Shell scripting and changing group id

I may be wrong, but have you tried

. /usr/bin/newgrp

? That '.' at the beginning means it won't fork a new process. Just an idea...

James
GARDENOFEDEN> create light
Belinda Dermody
Super Advisor

Re: Shell scripting and changing group id

Thanks Santos, your response is correct and it solved my problems, it is amazing how long you work at a job and the new things that you learn each day. I read and searched, but didnt read deep enough.
Belinda Dermody
Super Advisor

Re: Shell scripting and changing group id

James W. Your answer doesnt fit, the ./ is to look here first or to source a file.
A. Clay Stephenson
Acclaimed Contributor

Re: Shell scripting and changing group id

Actually, if the users are members of both groups they should be able to do the cd without problem. I suspect the problem is permissions of the directories above OR the permissions of the mountpoint. If you examine all the mounted directories and everything is fine, umount the filesystems and examine the permissions of the mountpoint itself. Just to test this, I did exactly what you describe on a 10.20 box and it worked just as expected with directory permissions set to 770.

Clay
If it ain't broke, I can fix that.
Wodisch
Honored Contributor

Re: Shell scripting and changing group id

Hello,

if you have a first line in your script like this:
#!/usr/bin/sh

then you could set the SGID (group-id bit) on the script, "chgrp" it to the wanted group, and give execute permission to everybody (an read and execute for that group, of course).

HTH,
Wodisch
James Beamish-White
Trusted Contributor

Re: Shell scripting and changing group id

Sorry, didn't go down in typing:

./usr/bin/newgrp

. is what I meant, not ./

Sorry for the mistaking comunication.

Cheers,
James
GARDENOFEDEN> create light