LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-27-2005, 12:10 PM   #1
pdc
LQ Newbie
 
Registered: Oct 2005
Posts: 3

Rep: Reputation: 0
ksh and while loops


We are setting up a new server and I have to add accounts from our old server, 2000 - 3000, of them. I am trying to set up an adduser script which will read userdata from a file and then add there account.
I have set up a test server which is running Fedora 4 Core, the new server will be running this also.

The script I am using works fine on Tru64-Unix and I have messaged to, I hope so it will work on Redhat. The problem is it appears that in the:

while read -u3 line, line it isn't reading it. If I put the read -u3 line by itself and then echo $line I get the output of the file line it reads. put it back into the while statement and nothing appears to happen. No account added no errors meesages nothing.

I'm sure it has to be something simple I am doing but beats me if I can figure it out.

Here is the script and thanks for any help you can give.

#!/bin/ksh -ph
PATH=/sbin:/usr/sbin:/usr/bin:/tcb/bin
export PATH

umask 022

if [ `id -u` -ne 0 ]
then
echo 'Please su to root first.\n'
exit 1
fi

if test ! -x /usr/sbin/useradd
then
echo 'Error, /usr/sbin/useradd missing or not executable.\n'
exit 1
fi


trap 'exit 1' 1 2

#SET FILE NAME
exec 3< ./userdata

#add new line to the userlist
echo 'password, account, email' >> ./userlist

#####################################################
#HERE WE ARE GOING TO READ FROM A FILE - read DATA
# the file looks like this:
# FIRSTNAME LASTNAME USERNAME USERIDNUM
# $1 = FIRSTNAME
# $2 = LASTNAME
# $3 = USERNAME
# $4 = USERIDNUM
#####################################################
while read -u3 DATA
do
print doing
set $DATA
NAME=$1' '$2
FNAME=$1
LNAME=$2
USERNAME=$3
UID=$4
LOGGROUP=student
LSHELL=/bin/sh
SKEL=/usr/skel
echo $NAME
echo $FNAME


case "$USERNAME" in
[AaBb]*)
PARENT=/usr/users/student.A-B
;;
[CcDd]*)
PARENT=/usr/users/student.C-D
;;
[EeFfGg]*)
PARENT=/usr/users/student.E-G
;;
[HhIiJj]*)
PARENT=/usr/users/student.H-J
;;
[KkLl]*)
PARENT=/usr/users/student.K-L
;;
[MmNnOo]*)
PARENT=/usr/users/student.M-O
;;
[PpQqRr]*)
PARENT=/usr/users/student.P-R
;;
[SsTt]*)
PARENT=/usr/users/student.S-T
;;
*)
PARENT=/usr/users/student.U-Z
;;
esac

echo $PARENT

echo '\nAdding new user ' $NAME '\n'

if test \! -d /usr/spool/mail
then
mkdir -p /usr/spool/mail
chmod 1777 /usr/spool/mail
fi

/usr/sbin/useradd -m -u "${UID}" -g "${LOGGROUP}" -c "${NAME}" \
-d "${PARENT}/${USERNAME}" \
-s "${LSHELL}" -k "${SKEL}" ${USERNAME}

if [ "${?}" -ne 0 ]
then
echo 'Error, exiting useradd %1$s. Check /etc/passwd.\n' "${0}"
exit 1
fi

cd "${PARENT}"
if [ "${?}" -ne 0 ]
then
echo 'Unable to cd to parent directory %1$s\n' "${PARENT}"
exit 1
fi
if [ -d "${USERNAME}" ]
then
chmod 751 ${USERNAME}
fi

# Script to set up staff and faculty accounts for CAP,
#
echo $USERNAME >> /usr/local/majordomo/lists/students
echo $FNAME'.'$LNAME':'$USERNAME >> /usr/adm/sendmail/aliases
/usr/sbin/newaliases

/usr/local/bin/scmkpw $USERNAME

#add new line to the userlist
echo $USERNAME', '$FNAME'.'$LNAME'@simpson.edu' >> /usr/local/etc/userlist

#Set up student accounts for CAP and create file mbox
#and perform some small admin tasks
#
#
cd $PARENT
cd $USERNAME
rmdir bin
rm -rf system*
touch mbox
chown $USERNAME mbox
edquota -p standard -u $USERNAME


trap - 1 2
done
 
Old 10-27-2005, 05:32 PM   #2
pdc
LQ Newbie
 
Registered: Oct 2005
Posts: 3

Original Poster
Rep: Reputation: 0
I figured it out

Boy do I feel stupid. THe answer is the file that has the data for the user to be added needs to have a carriage return at the end of each and everyline. I had a one line file with no return and so the script didn't know what to do so it did nothing. Unfortunately it didn't tell why it didn't do anything. Oh well, at least I got it figured out.
 
Old 10-29-2005, 05:13 PM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Your problem really is that you probably don't have a real Korn shell on your Redhat box. The pdksh that's usually installed is a pretty poor implementation, especially when you can get the real thing now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
while loops + while : blizunt7 Linux - General 3 12-04-2004 06:27 PM
variable with while loops michael_util Programming 4 08-16-2004 01:07 PM
foreach loops chunky Linux - General 2 07-02-2004 12:49 PM
loops JMK Linux - Newbie 11 04-09-2004 06:30 PM
Functions And Loops petercool Programming 14 08-08-2003 11:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration