[comp.unix.questions] newgrp in shell programs

bruno@sdcc10.ucsd.EDU (Bruce W. Mohler) (07/21/89)

Is it possible to do a newgrp near the beginning of
a shell program (especially one that has been started
by cron)?  Everything that I've tried has failed (ie.,
the shell program stops right at the point that it does
the newgrp).

I understand that newgrp creates a new shell process,
but knowing this has not helped me to figure out whether
what I want to do is possible...

I've tried to RTM before asking this (going thru all of
Sys Admin UNIX manuals we have as well as all of the 
"after-markey" Sys Admin books that we have on site).

Local security measures prevent me from using a "generic"
or impersonal userid (like lpadm) which has the group to
begin with, then letting that userid "own" the cron entries.
My only alternative (as far as I know) is to find some way 
to newgrp in these shell programs.

Environment: CCI Tahoe boxes (UNiSYS lables)
	     UN|X OS level 2.21 (which is a mutation of mostly
		BSD 4.2 with some SYSV.2 thrown in to make 
		things fun)
	     Shell: plain (good ole) Bourne

All suggestions and directions are appreciated, in advance!!!!
-- 
Bruce W. Mohler
Systems Programmer (aka Staff Analyst)
bruno@sdcc10.ucsd.edu
voice: 619/586-2218

jiii@visdc.UUCP (John E Van Deusen III) (07/22/89)

I have always wanted to ask this, and since Mr. Mohler has brought up
the subject:

	What if you login, su (one or more times) to another id that
	belongs to some other group, and then invoke newgrp with no
	options?

Do you end up in with the gid of the original login and the uid of
the latest su?

With respect to article <124@sdcc10.ucsd.EDU> bruno@sdcc10.ucsd.EDU
(Bruce W. Mohler), I believe the couth way to invoke a command from
crontab is to use su -c.
--
John E Van Deusen III, PO Box 9283, Boise, ID  83707, (208) 343-1865

uunet!visdc!jiii

bruno@sdcc10.ucsd.EDU (Bruce W. Mohler) (07/22/89)

In article <124@sdcc10.ucsd.EDU>, bruno@sdcc10.ucsd.EDU (Bruce W. Mohler) writes:
> Is it possible to do a newgrp near the beginning of
> a shell program (especially one that has been started
> by cron)?  ...
> 
> I understand that newgrp creates a new shell process,
> but knowing this has not helped me to figure out whether
> what I want to do is possible...
> 
> ...
>
> All suggestions and directions are appreciated, in advance!!!!

Thanks to Ihor Kinal and Paul Hite for providing me
2 different answers to my problem.  The answer that
best solves my problem is

 --> From: ijk@cbnewsh.ATT.COM (ihor.j.kinal)
 --> 
 --> Here's one thing that comes to mind [I've tried it and it does work]"
 --> 
 --> newgrp NEW_GROUP <<!
 --> 
 --> shell script goes here
 --> 
 --> !
 --> 
 --> --------------------
 --> Of course, when you're done, you're logged off the machine
 --> 

Thanks again!
-- 
Bruce W. Mohler
Systems Programmer (aka Staff Analyst)
bruno@sdcc10.ucsd.edu
voice: 619/586-2218

john@chinet.chi.il.us (John Mundt) (07/22/89)

In article <127@sdcc10.ucsd.EDU> bruno@sdcc10.ucsd.EDU (Bruce W. Mohler) writes:
>In article <124@sdcc10.ucsd.EDU>, bruno@sdcc10.ucsd.EDU (Bruce W. Mohler) writes:
>> Is it possible to do a newgrp near the beginning of
>> a shell program (especially one that has been started by cron)?
>
>Thanks to Ihor Kinal and Paul Hite for providing me
>2 different answers to my problem.  The answer that
>best solves my problem is
> --> From: ijk@cbnewsh.ATT.COM (ihor.j.kinal)
> --> Here's one thing that comes to mind [I've tried it and it does work]"
> --> newgrp NEW_GROUP <<!
> --> shell script goes here
> --> !
> --> --------------------
> --> Of course, when you're done, you're logged off the machine


You really should't get logged off, but if it's a problem,  you can put 
the whole mess inside of a subshell so that you'll get your old prompt 
back afterwards:

(
 newgrp NEW_GROUP <<!
	 shell script goes here
 !
)

Probably could do an exec newgrp... and save a process as well.


-- 
---------------------
John Mundt   Teachers' Aide, Inc.  P.O. Box 1666  Highland Park, IL
john@chinet.chi.il.us
(312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem