[HPADM] SUMMARY creating user IDs

From: Paveza, Gary (gary.paveza@AIG.COM)
Date: Wed Jun 19 2002 - 09:22:51 EDT


As usual there were tons of helpful replies. Most concerned the use of
useradd. I had been aware of the utility, but was looking more for a
general script. I was hesitant to just edit /etc/passwd by hand. SAM
(while just a tool to manage the file) could do the job, for the number of
entries I had to make on several machines was just not worth it.

What I ended up doing was the following:

On the machine that I was taking the IDs from, I copied /etc/passwd to
another name and stripped out any users I did not want to duplicate (root,
etc). I then ftp'd this file to the other systems. Using vi, I read this
file into /etc/passwd. Since I only have about 5 or 6 GIDs, I added them in
manually.

I then ran the following script to create the home directories and minimal
files. I realize this could have been done more efficiently, but wanted
each step spelled out in the script for later review by junior admins. Note
for our site, only UIDs between 200 and 600 are valid for users at this
time.

#!/usr/bin/sh
#
cat /etc/passwd | while read line
do
   USERNAME=$(echo $line | awk -F : '{print $1}')
   UID=$(echo $line | awk -F : '{print $3}')
   GID=$(echo $line | awk -F : '{print $4}')
   if [ $UID -gt 200 -a $UID -lt 600 ]
   then
      if [ ! -d /home/$USERNAME ]
      then
         GROUPNAME=$(cat /etc/group | grep $GID | awk -F : '{print $1}')
         mkdir /home/$USERNAME
         chown $USERNAME:$GROUPNAME /home/$USERNAME
         chmod 711 /home/$USERNAME
         cp /etc/skel/.cshrc /home/$USERNAME
         chown $USERNAME:$GROUPNAME /home/$USERNAME/.cshrc
         cp /etc/skel/.exrc /home/$USERNAME/.exrc
         chown $USERNAME:$GROUPNAME /home/$USERNAME/.exrc
         cp /etc/skel/.login /home/$USERNAME/.login
         chown $USERNAME:$GROUPNAME /home/$USERNAME/.login
         cp /etc/skel/.profile /home/$USERNAME/.profile
         chown $USERNAME:$GROUPNAME /home/$USERNAME/.profile
      else
         echo "User: $USERNAME UID:$UID GID:$GID"
      fi
   fi
done

> -----Original Message-----
> From: Paveza, Gary [SMTP:gary.paveza@AIG.COM]
> Sent: Tuesday, June 18, 2002 9:23 AM
> To: 'HP9000 Admin'
> Subject: [HPADM] creating user IDs
>
> Is there an easy way to create user IDs on a system without going through
> SAM? I have a need to move (copy) quite a few user IDs from one machine
> to
> another and am hoping there is an easier way than just recreating them one
> by one. No NIS or anything, we only use /etc/passwd.
>
> Does anyone have a script written to simply adding users from the command
> line?
>
> --
> ---> Please post QUESTIONS and SUMMARIES only!! <---
> To subscribe/unsubscribe to this list, contact
> majordomo@dutchworks.nl
> Name: hpux-admin@dutchworks.nl Owner:
> owner-hpux-admin@dutchworks.nl
>
> Archives: ftp.dutchworks.nl:/pub/digests/hpux-admin (FTP, browse
> only)
> http://www.dutchworks.nl/htbin/hpsysadmin (Web, browse &
> search)

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:14 EDT