#!/bin/bash
if [ ! -f /mnt/userfile ]; then
echo "the userfile not exist"
exit 0
fi
if [ ! -f /mnt/passfile ]; then
echo "the passfile not exist"
exit 0
fi
MAXUSERLINE=$(cat /mnt/userfile |wc -l)
MAXPASSLINE=$(cat /mnt/passfile |wc -l)
if [ "$MAXUSERLINE" != "$MAXPASSLINE" ]; then
echo "the two file is not equal"
exit 0
fi
for NUM in $(seq 1 $MAXUSERLINE)
do
USER=` sed -n ${NUM}p /mnt/userfile`
PASS=` sed -n ${NUM}p /mnt/passfile`
useradd $USER &>/dev/null
if [ "$?" != "0" ]; then
echo "the user is exist"
else
echo $PASS | passwd --stdin $USER
fi
done
if [ ! -f /mnt/userfile ]; then
echo "the userfile not exist"
exit 0
fi
if [ ! -f /mnt/passfile ]; then
echo "the passfile not exist"
exit 0
fi
MAXUSERLINE=$(cat /mnt/userfile |wc -l)
MAXPASSLINE=$(cat /mnt/passfile |wc -l)
if [ "$MAXUSERLINE" != "$MAXPASSLINE" ]; then
echo "the two file is not equal"
exit 0
fi
for NUM in $(seq 1 $MAXUSERLINE)
do
USER=` sed -n ${NUM}p /mnt/userfile`
PASS=` sed -n ${NUM}p /mnt/passfile`
useradd $USER &>/dev/null
if [ "$?" != "0" ]; then
echo "the user is exist"
else
echo $PASS | passwd --stdin $USER
fi
done