1847474 Members
2955 Online
110265 Solutions
New Discussion

Re: Add NIS user script

 
Angie_1
Regular Advisor

Add NIS user script

I would add a user through SAM, Add User, Add NIS user, but it doesn't create home directories unlike adding a local user.
So I need some guidance with writing a script to add a user to the NIS passwd.nis file, want to create a home directory for that user, and then copy some files into it.

Please tell me how to go about doing this. Case statements? If statements.. I am so confused.

Thanks...Angie
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Add NIS user script

This is a tricky problem because it greatly depends upon your environment. Typically, SAM can create a home directory on the NIS master server but generally you want a home directory elsewhere or maybe on multiple hosts. The most typical configuration is that the home directories are automounted and NIS maintains the automounter maps. In that scenario, no matter where a user logs in, his home directory is magically mounted although it might actually reside on a node far, far away.

You could script a remsh to a remote host to create the home directory.
If it ain't broke, I can fix that.
Angie_1
Regular Advisor

Re: Add NIS user script

Ok well the home directory is going to be on an NFS mount directory.

So I need help getting started on writing the script... like I am new to script writing anything real complex. Just need guidance on getting started.

Thx..Angie
Shannon Petry
Honored Contributor

Re: Add NIS user script

First, you need to change your logic, specially since your new.
Instead of having a user added to NIS from your scripts maintain SAM for this purpose, and make a script to deal with home directories.

If your using an automounter, then the problem is a bit more complex, but similar enough. I'll assume your using automounter and auto.home for users in my example. For basics though, remember a script is top down as with typing the commands manually.

#!/bin/sh
##########
echo "enter a user to make a home for"
read NEWUSR
TST=`grep $NEWUSR /etc/passwd|awk -F: '{print $1}'`
# Making sure there is such a user
if [ "${TST}x" = "x" ] ; then
echo "No such user $TST"
exit 1
elif [ "${TST}" = "NEWUSR" ] ; then
echo "Have user $TXT, going to process"
else
echo "unknown error. exiting"
fi# Have the user, so make the stuff...
GRP=`grep $NEWUSR /etc/passwd|awk -F: '{print $3}'`
#using GID is same as group name, and this is much easier
echo "$NEWUSR hostname:/export/$NEWUSR" >>/etc/auto.home

mkdir /export/$NEWUSR
chmod 755 /export/$NEWUSR
cp -p /etc/skel/.??* /export/$NEWUSR

chown -R $NEWUSR:$GRP /export/$NEWUSR

cd /var/yp
make auto.home


Of course directories dont match yours, and Im sure you need to make lots of modifications, you may be using ypmake instead of make, etc.. The example is to show basics in scripting. For info on the commands and routines in shells type
% man csh
% man sh
% man ksh

Man pages are really our friends, just tend to be dry at times.

Regards,
Shannon
Microsoft. When do you want a virus today?