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 2ndset 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"
fiif [ `echo $USER | wc -c` -gt 8 ]
then
## Convert the new user to 8 chars
USER=`echo $USER | awk '{ print substr($1,1,8) }'`
fiif [ -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=""
fifidone## 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>&1echo "\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>&1echo "\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?