1837257 Members
2411 Online
110115 Solutions
New Discussion

newgrp

 
Gary L. Paveza, Jr.
Trusted Contributor

newgrp

I have several users on my system which are members of several groups. They need to be able to switch between their groups (as defined by /etc/groups) when in certain areas so that files are created using the correct group ID. newgrp seems to do this, however, I'm trying to automate it. They have a file which they must source each time they change application "levels". In this file, all kinds of variables are set, and I'd like newgrp to be in there as well. The problem is that anything in the script after the newgrp command is discarded. While making it the last line of the file makes that problem go away, when this file is then sourced from within a script, the part of the script after the sourcing is discarded. Anyone know of a way to do this?
3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: newgrp

NAME
newgrp - switch to a new group

The newgrp command changes your group ID without changing your user ID
and replaces your current shell with a new one.



Its a command to be executed by the user, replacing the shell. Sourcing it would not seem the right approach.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Gary L. Paveza, Jr.
Trusted Contributor

Re: newgrp

It does function however. Maybe it's not the right command to do what I need to do. Basically, I need to switch the default gid of the process.
Michael Steele_2
Honored Contributor

Re: newgrp

Sounds like you've got several processes all with unique groups. Identifying groups by process should be easy enough since processes will contain the UID and GID.

ps -j (* pgid *)

Something like:

GPID=$(ps -j | grep -i process_name| awk '{ print $4 )'

Then,

newgrp $GPID
Support Fatherhood - Stop Family Law