useradd - exclude login from home directory path

OS: HP-UX 11.11

We use an application that requires every user's home directory path to be /user/application/data, but I can't seem to keep the useradd command from appending the new user's login ID to the default home path.

I want to see:

sammy:*:125:1000::/home/sww/dtest:/sbin/sh

but instead, I see

sammy:*:125:1000::/home/sww/dtest/sammy:/sbin/sh


Any ideas?

Thanks.
crcevansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
Use the -d dirname along with the useradd command
0
crcevansAuthor Commented:
I want it to default, instead of entering it every time I add a user. I want to be able to enter

useradd userid

without any options specified, and it default to the correct home directory.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

crcevansAuthor Commented:
Thanks. I've already set those options with the -D command. Here's the output:

*****
# useradd -D
GROUPID  1000
BASEDIR  /home/sww/dtest
SKEL     /etc/skel
SHELL    /sbin/sh
INACTIVE -1
EXPIRE
CHOWN_HOMEDIR no
*****

Note that with the current defaults set with the useradd -D command, using

# useradd sammy

results in

sammy:*:125:1000::/home/sww/dtest/sammy:/sbin/sh

Note that "sammy" is still appended to the base directory. This is the behaviour I want to modify.
0
omarfaridCommented:
The man page says that it add the username to the base dir. I don't think that you can change it.
0
crcevansAuthor Commented:
I should have mentioned in my original post that I'd already read through the man page, and done a good bit of Googling in search of a solution.

Surely someone has had an application that requires a static home directory, and knows how to default this behaviour...
0
chingmdCommented:
At that point, I would alias or script the useradd command to ensure the same results each time.

alias mkuser 'useradd -d /home/application/data \!*'

Add what ever options you want too.  


Or if you need multiple people to use it, then create a script.

0
crcevansAuthor Commented:
The alias method works great. Do you know of a way to incorporate adding user details, such as full name, etc, in the command line?

mkuser flname fname lname
0
omarfaridCommented:
A shell script would do.

in mkuser

useradd -d /user/application/data $*

The $* refers to the script arguments ($1, $2, etc)
0
crcevansAuthor Commented:
In mkuser I have

     useradd -d /home/sww/dtest $1 -c $2

but

     #mkuser sammy "sam williams"

returns: "too many arguments"

What am I doing wrong?
0
omarfaridCommented:
If you run in mkuser the code below

c=1
while test $c -le $#
do
        eval echo $"$c"
        c=`expr $c + 1`
done

What do you see? Please post output.
0
crcevansAuthor Commented:
Do I add that below the already existing command, or only have the above text in the file?
0
omarfaridCommented:
Please comment your code for the time being and let my code run with the same arguments you passed to the script.
0
crcevansAuthor Commented:
Sweet.

# ./mkuser sammy "sam williams"
sammy
sam williams
0
omarfaridCommented:
As you can see, the shell removed the quotations before and after.

Shell interpret " and space. so try the following:

./mkuser sammy \"sam\ williams\"

Here the \ tells shell to ignore processing " and space and leave them as is.

0
crcevansAuthor Commented:
# ./mkuser sammy \"sam\ williams\"
Too Many Arguements specified

Any ideas?
0
omarfaridCommented:
Is this with my code or your original code?
0
crcevansAuthor Commented:
My original code.

Also,

# ./mkuser sam sam_williams
Too Many Arguements specified
0
omarfaridCommented:
can you run the following and post the output?

sh +x  mkuser sam sam_williams
0
crcevansAuthor Commented:
# sh +x  mkuser sam sam_williams
Too Many Arguements 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>] <login>
Usage: useradd -D [-g <group>] [-b <base dir>] [-f <inactive>] [-e <expire>] [-r <yes|no>]
0
omarfaridCommented:
Ok,

can you put echo before useradd and run

sh +x  mkuser sam sam_williams


and post output


0
crcevansAuthor Commented:
# sh +x  mkuser sam sam_williams
useradd -d /home/sww/dtest sam -c sam_williams
0
omarfaridCommented:
I have tested your command on two systems one pass and the other fail

Please put the user name as the last thing, like:

useradd -d /home/sww/dtest  -c sam_williams sam

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crcevansAuthor Commented:
That works great. Thanks for all your effort. It looks like the comment text can't accept spaces. I get the "too many arguments" message. I can work around this by using an underscore, sam_williams_tulsa, etc.

So finally, I have the following in my mkuser script:

useradd -d /home/sww/dtest -c $1 $2

with a syntax of ./mkuser comment_text userid

0
crcevansAuthor Commented:
Especially for newbies, make sure you explicitly state where lines or code, and other such info is to be placed. IE, if I need to add "echo" to the script, do I add it on it's own line, or prepend it to the existing command line.

Thanks so much!
0
omarfaridCommented:
When I said "can you put echo before useradd ...", I meant before on the  same line
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.