Operating System - HP-UX
1752815 Members
5992 Online
108789 Solutions
New Discussion

Re: ksh - problems with comment parameter in useradd

 
Gary Cooper_1
Esteemed Contributor

ksh - problems with comment parameter in useradd

I am trying to user useradd in a ksh script...

PG_USERNAME=postgres

PG_USER_ID=26

PG_GROUP_ID=26

PG_USER_SHELL='/bin/ksh'

PG_USER_DIR='/home/postgres'

PG_USER_COMMENT="\"Postgres administration account"\"

:

echo "useradd -u $PG_USER_ID -g $PG_GROUP_ID -d $PG_USER_DIR -m -s $PG_USER_SHELL -c $PG_USER_COMMENT $PG_USERNAME"

useradd -u $PG_USER_ID -g $PG_GROUP_ID -d $PG_USER_DIR -m -s $PG_USER_SHELL -c $PG_USER_COMMENT $PG_USERNAME

:

 

 

When I run the script, I get...

 

04-Jun-2015 12:37:19: Info: Creating Postgres user 'postgres' with UID '26'...

useradd -u 26 -g 26 -d /home/postgres -m -s /bin/ksh -c "Postgres administration account" postgres

Too Many Arguments specified

Usage: useradd [-u <uid> [-o]] [-g <group>] [-G <group>[,<group...>]] [-d <dir>] [-s <shell>] [-c <comment>] [-m [-k <skel dir>]] [-f <inactive>] [-e <expire>] [-r <yes|no>] [-p <encrypted-password>] [-t <template>] [-P -S <alternate password file>] <login>

Usage: useradd -D [-g <group>] [-b <base dir>] [-f <inactive>] [-e <expire>] [-r <yes|no>] [-M <yes/no>] [-k <skel dir>] [-O <yes/no>] [-s <shell>] [-c <comment>] [-t <template>]

04-Jun-2015 12:37:19: ERROR: Unable to create Postgres user postgres, error: 2

root@devp51:#

 

Any ideas?

 

Many thanks,

 

Gary

3 REPLIES 3
mjkgard
Occasional Visitor

Re: ksh - problems with comment parameter in useradd

PG_USER_COMMENT=\"Blah\"

Gary Cooper_1
Esteemed Contributor

Re: ksh - problems with comment parameter in useradd

PG_USER_COMMENT=\"Postgres administration account\"

 

Then when I run it...

root@devp51:# ./create_pg_user

./create_pg_user[74]: administration: not found

04-Jun-2015 14:25:51: Info: Creating Postgres user 'postgres' with UID '26'...

useradd -u 26 -g 26 -d /home/postgres -m -s /bin/ksh -c postgres

Either -D or user must be specified

Usage: useradd [-u <uid> [-o]] [-g <group>] [-G <group>[,<group...>]] [-d <dir>] [-s <shell>] [-c <comment>] [-m [-k <skel dir>]] [-f <inactive>] [-e <expire>] [-r <yes|no>] [-p <encrypted-password>] [-t <template>] [-P -S <alternate password file>] <login>

Usage: useradd -D [-g <group>] [-b <base dir>] [-f <inactive>] [-e <expire>] [-r <yes|no>] [-M <yes/no>] [-k <skel dir>] [-O <yes/no>] [-s <shell>] [-c <comment>] [-t <template>]

04-Jun-2015 14:25:51: ERROR: Unable to create Postgres user postgres, error: 2

root@devp51:#

 

Patrick Wallek
Honored Contributor

Re: ksh - problems with comment parameter in useradd

Here is what I got to work, based on your script snippet:

 

#!/usr/bin/ksh -x
PG_USERNAME=pwwtest1

PG_USER_ID=2600

PG_GROUP_ID=2600

PG_USER_SHELL='/bin/ksh'

PG_USER_DIR='/home/pwwtest1'

PG_USER_COMMENT="Postgres administration account"

useradd -u $PG_USER_ID -g $PG_GROUP_ID -d $PG_USER_DIR -m -s $PG_USER_SHELL -c "$PG_USER_COMMENT" $PG_USERNAME

Notice that I just have one set of double-quotes around the PG_USER_COMMENT string and then I put double quotes around the variable $PG_USER_COMMENT in the command itself.

 

This worked and created the ID for me.