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?
 
omarfaridConnect With a Mentor Commented:
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
chingmdConnect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.