LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2004, 05:48 PM   #1
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Rep: Reputation: 0
Need Help!!!


This is my script!
#Get information from userlist file!
cat ${NEW_USERS} | \
while read USER PASSWORD GROUP FULLNAME

#Process adding users and groups, also shows information after users have been added!
do
if [ -z "`grep ^${GROUP}: /etc/group`" ];then
groupadd ${GROUP}
echo "Group ${GROUP} successfully added."

fi
if [ -z "`grep ^${USER}: /etc/passwd`" ] && [ ${#USER} -lt 6 ] && [ ${#PASSWORD} -ge 5 ];
then
useradd -g ${GROUP} -p ${PASSWORD} -c ${FULLNAME} -m -d ${HOME_BASE}${USER} ${USER}


echo "User ${USER} successfully added."

else
echo "Can not add user ${USER}--"The user has existed or invaild!!""


fi
The Problem is I just can read the format like: USER PASSWORD GROUP FULLNAME in userlist file
but if I changed the format like: USER:PASSWORD:GROUP:FULLNMAE, then it doesn't work, so how I could I read this format,please give me a hint, I used gawk,but still doesn't work!
 
Old 04-06-2004, 05:52 AM   #2
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Original Poster
Rep: Reputation: 0
need help!

need help!
 
Old 04-06-2004, 09:17 PM   #3
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Original Poster
Rep: Reputation: 0
need help

need help
 
Old 04-07-2004, 12:43 AM   #4
gauge73
Member
 
Registered: Jan 2003
Location: Dallas, TX
Distribution: Fedora Core 4
Posts: 420

Rep: Reputation: 30
Seems like you should be able to use some variation of the following to get the results you want...

Code:
x=0
while [ $x -lt `wc -l | sed 's/[^0-9]//g'` ] ; do
USER=`awk -v var=$x -F":" 'NR==var {print $1}' $NEW_USERS_FILE`
PASSWORD=`awk -v var=$x -F":" 'NR==var {print $2}' $NEW_USERS_FILE`
GROUP=`awk -v var=$x -F":" 'NR==var {print $3}' $NEW_USERS_FILE`
FULLNAME=`awk -v var=$x -F":" 'NR==var {print $4}' $NEW_USERS_FILE`
# ...
# do whatever you need to do with the variables
# ...
x=$x+1
done
Hope this helps (I'm a bit of a newbie, so it certainly might not.

Last edited by gauge73; 04-07-2004 at 10:09 AM.
 
  


Reply



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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:30 PM.

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
Open Source Consulting | Domain Registration