LinuxQuestions.org
Visit Jeremy's Blog.
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 03-22-2004, 06:37 PM   #1
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Rep: Reputation: 0
Question Help me!!!!!shell script question!!!!!!


Here is my script code:
DATE=`/bin/date`
NEW_USERS="/script/userlist"
HOME_BASE="/home/"

cat ${NEW_USERS} | \
while read USER PASSWORD GROUP FULLNAME
do
if [ -z "`grep ^${GROUP}: /etc/group`" ];then
groupadd ${GROUP}
echo "Group ${GROUP} successfully added."
fi
if [ -z "`grep ^${USER}: /etc/passwd`" ]
then
useradd -g ${GROUP} -p ${PASSWORD} -c ${FULLNAME} -m -d ${HOME_BASE}${USER} ${USER}
echo "User ${USER} successfully added."
fi
if [ $? -eq 0 ] ; then
echo "User_fullname:${FULLNAME} Account_name:${USER} user_id:$uid group_name:${GROUP} group_id:$gid $DATE" >> Report
fi
done

This script should be add users from userlist, and then produce user's information to a Report file, my problem is after a user(John) has been added, the information in Report file like this
User_fullname:John Account_name:john user_id: group_name: operation group_id: Tue Mar 23 12:30:28 NZST 2004
But there is no user_id and group_id on it, how could I get these two information, please help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2 ,another question is if I want to users password that in the userlist must over 6 characters , group name just can be "marketing" "operation" 'business", otherwise they are invaild users. How could I do that, hope my problem is not very difficult!

Last edited by yulitao; 03-22-2004 at 07:16 PM.
 
Old 03-23-2004, 03:45 AM   #2
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Original Poster
Rep: Reputation: 0
please help me!
 
Old 03-23-2004, 03:40 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Code:
DATE=`/bin/date`
NEW_USERS="/script/userlist"
HOME_BASE="/home/"

cat ${NEW_USERS} | \
while read USER PASSWORD GROUP FULLNAME
do
if [ -z "`grep ^${GROUP}: /etc/group`" ];then
groupadd ${GROUP}
echo "Group ${GROUP} successfully added."
fi
if [ -z "`grep ^${USER}: /etc/passwd`" ]
then
useradd -g ${GROUP} -p ${PASSWORD} -c ${FULLNAME} -m -d ${HOME_BASE}${USER} ${USER}
SUCCESS=$?
echo "User ${USER} successfully added."
fi
if [ ${SUCCESS} -eq 0 ] ; then
USERID=$(id -ur ${USER})
GROUPID=$(id -gr ${GROUP})
echo "User_fullname:${FULLNAME} Account_name:${USER} user_id:${USERID} group_name:${GROUP} group_id:${GROUPID} $DATE" >> Report
fi
done

Last edited by Hko; 03-23-2004 at 03:42 PM.
 
  


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
shell script question Whiteghost Programming 17 09-10-2005 06:52 PM
Shell script question paraiso Linux - Newbie 2 05-15-2005 01:55 AM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
Shell script question. siaful Linux - Newbie 1 04-29-2004 05:01 PM
Shell script question rytrom Linux - Newbie 4 01-28-2004 07:20 AM


All times are GMT -5. The time now is 04:59 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration