Operating System - HP-UX
1823175 Members
3688 Online
109647 Solutions
New Discussion юеВ

Re: Unix logon menu script question

 
SOLVED
Go to solution
Jim Tropiano_1
Frequent Advisor

Unix logon menu script question

1) Thanks to all the replied that help me with the last question.
I need to be able to modify the /etc/group file from a shell script. I can add user xxxusr01 to the supplemental group mc_xxx01 using the command

usermod -G mc_xxx01 xxxusr01

but I cannot find a command to use in a shell script to remove a user from a group.

we do not want to edit the etc/group file directly.
10 REPLIES 10
Joseph Loo
Honored Contributor

Re: Unix logon menu script question

hi,

do u want to remove user from primary or secondary group?

regards.
what you do not see does not mean you should not believe
Jim Tropiano_1
Frequent Advisor

Re: Unix logon menu script question

I am thinking it would be the secondary group.
Rajeev  Shukla
Honored Contributor

Re: Unix logon menu script question

The only way to add or remove a user from a group is by usermod only.
First do groups on that user
groups usr1 (to list the groups it belong to)
then
usermod -G grp1,grp2,grp3,grp4 usr1
will add the user to grp1, grp2,grp3 and grp4 group.
Now say you want to remove him from grp4 then do
usermod -G grp1,grp2,grp3 usr1

Cheers
Rajeev
Niraj Kumar Verma
Trusted Contributor

Re: Unix logon menu script question

seems to be very good idea

-Niraj
Niraj.Verma@philips.com
Ermin Borovac
Honored Contributor
Solution

Re: Unix logon menu script question

I don't think usermod can selectively remove a user from a single group. It can only redefine group membership.

You can try using SAM's backend command grpusrs.

# /usr/sam/lbin/grpusrs -d -l

This would delete from not affecting other members of .
Jim Tropiano_1
Frequent Advisor

Re: Unix logon menu script question

We will be runnig this from a menu.

The user will logon and the menu selection will allow them to selected what they have access to.
Example
select enviroment

1 - TEST
2 - Prod support
3 - DEV
4 - DEV01
5 EXIT

If they select one the they get put into group TEST. When they are done with TEST they get back to the menu and can select another environment. Let say 3
Now we want to delete them from group TEST and add them to group DEV
Suraj Singh_1
Trusted Contributor

Re: Unix logon menu script question

This would mean that any selection would lead the user to a different secondary group.

You can use 'case' here, something like:

case "$selection" in
TEST ) usermod -G test user;;
Prod support ) usermod -G prod user;;
DEV ) usermod -G dev user;;
DEV01 ) usermod -G dev01 user;;
...
...

Regards,
Suraj

What we cannot speak about we must pass over in silence.
Jim Tropiano_1
Frequent Advisor

Re: Unix logon menu script question

We would use the case statement on their selection but when they return to the menu we would like to delete that group they were just in. Also if they select a group we would like to add that grop as a secondary group. then we would enviromental variables to the group they are in.
Denver Osborn
Honored Contributor

Re: Unix logon menu script question

Jim,

Are you looking to create a menu that the user sees up login? When they login and select their menu option, do you plan to have them exit the menu to a shell or will the menu "su" to their account?

One problem here is what to do if the script terminates before the user's original groups are restored. Maybe if you provide a bit more detail on who/what/why... someone might be able to throw something better together.

Anyhow, sounds to me like you'd want the script to collect the user's info then loop the menu and run your commands. upon exiting the loop, set the users group back to the orginal settings.

example
----

USER=`logname`
OLD_GROUPS=`groups`

rval=0
until [ $rval -eq 1 ];do

cat << EOF
your menu stuff...
OPT1 this is option 1
OPT2 this is option 1
EXIT
EOF

case $SELECT in
OPT1) your add grp cmds
and other user commands, etc
;;
OPT2) your add grp cmds
and other user commands, etc
;;
EXIT) rval=1
;;

done

your commands to set groups to $OLD_GROUPS
and whatever else you need to do...

----


hope this helps,
-denver
Denver Osborn
Honored Contributor

Re: Unix logon menu script question

doh! I know, I know... forgot "esac" before "done"

you know what I meant :)