[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cron jobs, env vars, and group ID ... oh my

From: Greg Wooledge
Subject: Re: Cron jobs, env vars, and group ID ... oh my
Date: Wed, 28 Nov 2012 12:50:39 -0500
User-agent: Mutt/

On Wed, Nov 28, 2012 at 09:10:02AM -0800, Mun wrote:
> I need to run a script via cron that in turn launches a script to set up the
> requisite environment variables needed for a successive script that is called.
> Moreover, I need to change my group ID in order for the scripts called within
> the cron job to run properly.

This belongs on help-bash, not bug-bash.

> #! /bin/bash
> newgrp group1
> id -g -n             // This shows my login group ID, not group1

Ah, the fundamental question here is "how does newgrp(1) work".

Quoting the HP-UX man page:

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

And a demonstration (from bash):

imadev:~$ id
uid=563(wooledg) gid=22(pgmr) groups=1002(webauth),208(opgmr)
imadev:~$ echo $$
imadev:~$ newgrp opgmr
imadev:~$ echo $$
imadev:~$ id
uid=563(wooledg) gid=208(opgmr) groups=22(pgmr),1002(webauth)
imadev:~$ exit
imadev:~$ echo $$

So, you can see that this is utterly useless in a script.  Try using
sudo(1) instead if it's available.

P.S., newgrp works very differently from within ksh, where it is a
shell builtin.  Still useless in a script, though.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]