Operating System - HP-UX
1832891 Members
2888 Online
110048 Solutions
New Discussion

useradd.sam - not creating home dirs

 
SOLVED
Go to solution
Fred Sanford III
Occasional Advisor

useradd.sam - not creating home dirs

Howdy Folks,

I have to add a large number of users to a system running hp-ux 11.11.

I've written a simple script that calls useradd.sam, because it allows me to assign a common password. The only downside is, it does not created the home directories.

Here is the command I am using:

/usr/sam/lbin/useradd.sam -m -u $NUID -p $PASSWORD -c "$FIRST $LAST" -s /usr/bin/ksh $USERNAME

I run the exact same command calling /usr/sbin/useradd, and the home dir is created, but I can't set the password.

Here are the defaults:

/usr/sam/lbin/useradd.sam -D
GROUPID 20
BASEDIR /home
SKEL /etc/skel
SHELL /sbin/sh
INACTIVE -1
EXPIRE
CHOWN_HOMEDIR yes

I am puzzled. Any ideas? Please let me know.

Thanks in advance!

Fred
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: useradd.sam - not creating home dirs

Hi Fred:

Interestinly, the 'useradd.sam' command is simply a symbolic link to '/usr/sbin/useradd'.

It would be useful to know the return code from the execution of the command both commands, too:

# /usr/sam/lbin/useradd.sam -m -u $NUID -p $PASSWORD -c "$FIRST $LAST" -s /usr/bin/ksh $USERNAME; echo $?

Regards!

...JRF...
Fred Sanford III
Occasional Advisor

Re: useradd.sam - not creating home dirs

Hi James,

I noticed the same thing which is why I am so puzzled.

Both commands returned a 0, so the command is executing successfully.

/usr/sam/lbin/useradd.sam -m -u 115 -p $PASSWORD -c "test user" -s /usr/bin/ksh testme2 ; echo $?
0

ll -d /home/testme2
/home/testme2 not found

/usr/sbin/useradd -m -u 116 -c "test user" -s /usr/bin/ksh testme3 ; echo $?
0

ll -d /home/testme3
drwxr-xr-x 2 testme3 users 96 Feb 25 09:56 /home/testme3

James R. Ferguson
Acclaimed Contributor
Solution

Re: useradd.sam - not creating home dirs

Hi (again) Fred:

And I too see the same behavior; viz. that using the symbolic link allows you to specify the '-p' switch whereas using the executable directly does not. This is in addition to the "side-effect" of not creating the home directories.

Thus, it seems that the underlying binary detects whether or not it is called by the name 'useradd.sam' or not. This is easily achieved when an executable calls 'realpath()' which discerns whether an absolute pathname names the same file or involves '.' or '..' characters or symbolic links.

A simple snippet of Perl code demonstates this:

# cat /tmp/somecode.pl
#!/usr/bin/perl
use Cwd qw(realpath);
my $who = realpath($0);
if ( $0 eq $who ) {
print "run as the real thing!\n";
}
else {
print "run as an alias!\n";
}
1;

# ln -s /tmp/somecode.pl /tmp/somecode

# /tmp/somecode
run as an alias!
# /tmp/somecode.pl
run as the real thing!

With regard to your case, it seems that you can't have your cake and eat it too.

Regards!

...JRF...
Fred Sanford III
Occasional Advisor

Re: useradd.sam - not creating home dirs

Well, not the answer I was hoping for, but the one I expected.

Thanks for taking the time.

Fred
Fred Sanford III
Occasional Advisor

Re: useradd.sam - not creating home dirs

See above.