[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: Bob Proulx
Subject: Re: Cron jobs, env vars, and group ID ... oh my
Date: Wed, 28 Nov 2012 10:52:22 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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

The 'newgrp' command spawns a new child shell.  After that child shell
exits the new group evaporates.  The rest of the script continues with
the previous id.  This is a common misunderstanding of how newgrp
works.  People often think it changes the current shell.  It does
not.  It stacks a child shell.

Basically, newgrp does not do what you thought it did.  It can't be
used in this way.

You might try having the newgrp shell read commands from a secondary

  newgrp group1 < other-script-file

Or you might consider using 'sudo' or 'su' for that purpose too.


reply via email to

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