Technical article 126734

How can I automate a new user creation with password on the failover UW7 or OSR6 server when adding that new user on the live server?

OpenServer 6.0.0UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3UnixWare 7.1.4Open UNIX 8

Written · Last revised

Problem

I have a live and a failover server environment setup.

Both servers are identical to each other in regards o the release and installation of SCO UnixWare 7 or Openserver 6.

Both servers have trusted equivalence for each other in the file /.rhosts.

rsh between the two servers is working fine.

When I create a new users on the live server, I would like that user to get migrated automatically with his password and home directory details to the failover server without me having to do anything for that user on the failover server.

Solution

You can achieve that using the following steps and scripts:

To archive this, it is best to add the user via a script and not through "scoadmin account manager".

In our example, the directory /local/user will be the working directory.

And the failover server is called "systemB"

1- You need to create an expect script "mkpass" to handle the interactive passwd command:

---- script number 1 (mkpass) with 755 file permission ----

#!/usr/bin/expect -f
# script name = mkpass
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "password:"
send "$password\r"
expect "password:"
send "$password\r"
expect eof
---------------------------------------------------------

2- you need to create a script to add a new user:

---- script number 2 (newuser) with 755 file permission ----

#!/bin/ksh
REMOTESVR=systemB
clear
echo "\nThis script will add a new user and synchronize them"
echo "with the Failover servers.\n"
while [ -z $USER ]
do
  echo "Please enter new username: \c"
  read USER
## To convert any Uppercase letters to lower case one
echo "\nChecking case, converting to lower case and setting"
echo "to 8 chars if necessary ...\n"
USER=`echo $USER | tr '[A-Z]' '[a-z]'`
CHECKUSERNAME=`grep "^$USER" /etc/passwd`
if [ `echo $USER | wc -w` -gt 1 ]
   then
      clear
      CHECKUSERNAME="tolong"
fi
if [ `echo $USER | wc -c` -gt 8 ]
   then
      ## Convert the new user to 8 chars
      USER=`echo $USER | awk '{ print substr($1,1,8) }'`
fi
if [ -z $CHECKUSERNAME ]
   then
   echo "\nThe username has been set to" $USER "continuing..\n"
   else
      clear
      if [ "$CHECKUSERNAME" = "tolong" ]
         then
             echo "Username is not in the correct format(Example:
             harrym) please re enter\n"
             USER=""
         else
             echo "Username already exists\n"
             USER=""
      fi
fi
done
## Creating the user with useradd command
while [ -z "$FULL" ]
do
  echo "Please enter the new user full name and comments: \c"
  read FULL
done
/usr/sbin/useradd -c "$FULL" -m `echo $USER | awk '{ print $1 }'`
echo "Enter password: \c"
read PASSWORD
/local/user/mkpass $USER $PASSWORD > /dev/null 2>&1
echo "\nSyncronising user with failover servers...\n"
ping $REMOTESRV 3 >/dev/null 2>&1
if [ "$?" != 0 ]
   then
       echo "Failover server not available, user could not
       be synchronized!!!!\n"
       exit 0
   else
       ap -dg $USER > /local/user/$USER.txt
       rcp /local/user/$USER.txt $REMOTESRV:/
       sleep 2
       rsh $REMOTESRV '/usr/sbin/ap -ro -f /local/user/$USER.txt'
       sleep 2
       find /home/$USER -print | cpio -ocvB | rsh
       $REMOTESRV "cd /; cpio -icvdum" > /dev/null 2>&1
echo "\synchronization completed....exiting ...."
fi
sleep 3
clear
----------------------------------------------------------
NOTES:     The "newuser" script is very basic. The idea is to show you
           the basic of its functionality. It can be modified and
           improved to your liking.

See also

TA109984: How can I automate the account creation and password assignment process on UnixWare 7?

TA125883: Unixware 7/OSR6: How can I copy files from one server to another?

From the Xinuos technical article database, record 126734. Reproduced with permission. The original is at www.sco.com/ta/126734, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.