newgrp in a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers newgrp in a script
# 1  
Old 01-08-2004
Error newgrp in a script

I want to do these commands in a script:
if the user name is 'toto' then the user switch to the group toto_group and then 2 others scripts are launched.
Unfortunately, after the command 'newgrp' the 2 scripts are not launched correctly.
But if I do the same, by hand, one line per one line, it works!! Why ?? I work on with a SUNOS5.7

Thanks for your help !
# 2  
Old 01-08-2004
I am not getting your problem, it would be nice if you can post your code here

Regards
JK
# 3  
Old 01-08-2004
Yes, my code is:

#! /bin/csh

set PATH_CPT = `pwd`;
set PRJ = '/home/myproject/'
echo "Changement de groupe UNIX touareg"
newgrp my_project &
## creation of the ANABE_CFG directory
if !( -d $PATH_CPT/ANABE_CFG ) then
mkdir $PATH_CPT/ANABE_CFG
cd $PATH_CPT/ANABE_CFG
mkdir CALIBRE
mkdir PROJECT
else echo " $PATH_CPT/ANABE_CFG directory already exists "
endif

stconf

icfb&
# 4  
Old 01-08-2004
The newgrp command fires up a subshell. When you run it by hand, the subshell reads the next commands. You are running newgrp in a script. The script continues to read the commands while the subshell does nothing.


You don't need newgrp anymore. It was needed when you could only be in one group at a time. Now you can be in many at a time. Type "groups" to see your list.

newgrp has been obsolete for over a decade. But this is the second question on newgrp in the past few weeks. Smilie
# 5  
Old 01-08-2004
There's a good reason for that. Guess the OP didn't catch it the first time you said this command is obsolete. Smilie

https://www.unix.com/showthread.php?s...ghlight=newgrp
# 6  
Old 01-08-2004
Yes, you said that the command is obsolete but I don't know haw to do what I want !!

To secure the account of my project we create a 'subroup'. So, everybody in the team belongs to group A but few persons belongs to group B. So that the UNIX right are not the same for everybody. If everybody can read all datas, only few persons are authorised to write on the project account. To do that, I though to use the command newgrp. When we work for the project, before launching applications, we do newgrp.

How can I do that without (or with ??) using newgrp ??!!

Thanks

Nathe
# 7  
Old 01-08-2004
For newgrp to work, the user must be listed in the group entry. But if the user is listed in the group entry, the login program will make the user a member of the group at login time. Thus newgrp is a no-op. I just tested this on Solaris. Try it yourself:
groups
newgrp somegrp
groups
This might be useful is a user was recently added to a group, I suppose. But the user some just sign off and on again. Or exec login or something.

Or you could be using group passwords. But there is no tool to assign them. Did you write one or something? There is no equivalent of /etc/shadow for group passwords. You would be leaving the encrypted password in plain sight. The manpage for newgrp warns against using group passwords. Group passwords were deprecated over a quarter of a century ago.

Doing what you want is trivial. I can't imagine how your got it work with newgrp but arranged for it to not work without newgroup. In fact, I strongly suspect that you are finished, but don't know it.

Everyone is in groupa. A few people are in groupb. Now you do:
chgrp groupb somefile
chmod 464 somefile

Now everyone can read somefile. Those folks (and only those folks) in groupb can write it. And all the groupb people need to do is logon. Forget about newgrp. It is that simple.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

2. Solaris

Newgrp fails on only 1 group

I have a handful of users who can't 'newgrp' to one specific group from Solaris 9 and 10 nodes and always get this prompt: newgrp: Password: We never get prompted by 20+ other groups and this group never prompts for a password from Red Hat Linux nodes. Authentication comes from AD and there's... (4 Replies)
Discussion started by: rnae20
4 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

How to set up newgrp on .profile?

Hello all, I am having an issue setting up an environment on .profile. I want to set up my .profile in that way that everytime I login to the host, it should automatically set up my group. I tried the folllowing but it doesn't work. It is on the solaris OS. HOSTNAME=$(hostname) if ] || ]... (14 Replies)
Discussion started by: Pateltiger
14 Replies

6. Shell Programming and Scripting

How to use newgrp or sg in user mode without password prompt?

Hi, Is it possible to call newgrp or sg from user mode without password prompt in a Linux script? Thank you. hce (2 Replies)
Discussion started by: hce
2 Replies

7. Shell Programming and Scripting

what is the right way to use newgrp in script

my requirement is $ id user o/p for the above command $ uid=1(user) gid=2(x) a user is involved in 3 groups x,y,z whenever the user try to execute a script, script should ask for the group as input from user ,assume the group he wants to change as Y and the rest of the... (3 Replies)
Discussion started by: ram_unx
3 Replies

8. Shell Programming and Scripting

Automating 'newgrp' command - how?

Hi, I have to add the 'newgrp' command to my login (.cshrc) script. The problem is that if I add it, it comes to infinite look, since newgrp opens new shell again and again. How to automate the newgrp when I have to login, and avoid that loop? Currently I'm thinking of a condition that... (2 Replies)
Discussion started by: moshmosh
2 Replies

9. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

10. UNIX for Advanced & Expert Users

newgrp command

I'd like to make an alias of commands which contains the command newgrp. exple: alias my_cmde newgrp toto; my_pg & this line doesn't work. why ? Thanks for your help (2 Replies)
Discussion started by: Nathe
2 Replies
Login or Register to Ask a Question