Operating System - HP-UX
1827318 Members
5600 Online
109961 Solutions
New Discussion

question on $usermod -G option

 
SOLVED
Go to solution
Shan_2
Advisor

question on $usermod -G option

Hi,
I am creating a shell script to assign secondary groups to a user.

I would like to know the exact usage of "usermod -G".

I have tried these syntax but all failed:

(1) # usermod -G usrgrp2, usrgrp3 user1
ERROR MESSAGE:
User name must be specified
Usage: usermod [-u [-o]] [-g [-G [, [-d [-m]] [-s ] [-c ] [-f <inactive>] [-e <expire>] [-l <new logname>] <login><BR /><BR />(2) # usermod -g usrgrp1 -G usrgrp2, usrgrp3 user1<BR />ERROR MESSAGE:<BR />User name must be specified<BR />Usage: usermod [-u <uid> [-o]] [-g <group> [-G <group>[,<group...> [-d <dir> [-m]] [-s <shell>] [-c <comment>] [-f <inactive>] [-e <expire>] [-l <new logname>] <login><BR /><BR />(3) # usermod -G "usrgrp2, usrgrp3" user1<BR />ERROR MESSAGE:<BR />Group usrgrp3 does not exist<BR />Group list specified with -G is invalid<BR /><BR />(4) # usermod -G "usrgrp2 usrgrp3" user1<BR />ERROR MESSAGE:<BR />Group usrgrp2 usrgrp3 does not exist<BR />Group list specified with -G is invalid<BR /><BR />(5) # usermod -G usrgrp2 -G usrgrp3 user1<BR />ERROR MESSAGE:<BR />Duplicate Option G<BR />Usage: usermod [-u <uid> [-o]] [-g <group> [-G <group>[,<group...> [-d <dir> [-m]] [-s <shell>] [-c <comment>] [-f <inactive>] [-e <expire>] [-l <new logname>] <login><BR /><BR /><BR />I have also tried to issue consecutive "usermod -G" but only the last group would be added as the secondary group. <BR /><BR />Any suggestion ?<BR />Thanks a lot!<BR /><BR />
2 REPLIES 2
Simon Hargrave
Honored Contributor
Solution

Re: question on $usermod -G option

Try the command without spaces after commas, eg: -

usermod -G group1,group2,group3 user1

instead of

usermod -G group1, group2, group3 user1

The manpage is slightly misleading, but with spaces the parameters will not be interpreted correctly.


Sy
Shan_2
Advisor

Re: question on $usermod -G option

Thank you Simon, it Works!