Hi Greg, Bob, Thanks for your replies. Please see my comments below.
On Wed, Nov 28, 2012 at 09:50 AM PST, Greg Wooledge wrote: GW> On Wed, Nov 28, 2012 at 09:10:02AM -0800, Mun wrote: GW> > I need to run a script via cron that in turn launches a script to set up the GW> > requisite environment variables needed for a successive script that is called. GW> > Moreover, I need to change my group ID in order for the scripts called within GW> > the cron job to run properly. GW> GW> This belongs on help-bash, not bug-bash. Oops, my apologies; I forgot about the help-bash list. I will post a variant of my original post to help-bash (without this group ID problem, since you folks have addressed that issue already). GW> > #! /bin/bash GW> > GW> > newgrp group1 GW> > id -g -n // This shows my login group ID, not group1 GW> GW> Ah, the fundamental question here is "how does newgrp(1) work". I see. I will try Bob's suggestion to read input from another file. Best regards, -- Mun GW> GW> Quoting the HP-UX man page: GW> GW> The newgrp command changes your group ID without changing your user ID GW> and replaces your current shell with a new one. GW> GW> And a demonstration (from bash): GW> GW> imadev:~$ id GW> uid=563(wooledg) gid=22(pgmr) groups=1002(webauth),208(opgmr) GW> imadev:~$ echo $$ GW> 8282 GW> imadev:~$ newgrp opgmr GW> imadev:~$ echo $$ GW> 4859 GW> imadev:~$ id GW> uid=563(wooledg) gid=208(opgmr) groups=22(pgmr),1002(webauth) GW> imadev:~$ exit GW> imadev:~$ echo $$ GW> 8282 GW> GW> So, you can see that this is utterly useless in a script. Try using GW> sudo(1) instead if it's available. GW> GW> P.S., newgrp works very differently from within ksh, where it is a GW> shell builtin. Still useless in a script, though.