LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-25-2004, 04:18 PM   #1
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Rep: Reputation: 0
Bash script!! need help!!!!!could be easy!


there is my script for addusers
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`" ] && [ ${#USER} -lt 6 ];
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

Currently it is working fine, what I want to add is a conculator, after added all users just show the numbers of added users and numbers of invalid users, please help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Old 03-25-2004, 04:32 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Ehmmm...... you really shouldn't start a new thread every time you ask a question on the same problem you are having, anyway, to declare a variable you can do

let number_of_users_added=0
let number_of_invalid_users=0


and to add one to a variable you can do

let number_of_users_added++

and

let number_of_invalid_users++

Just add these at the appropriate part of the script and output them when you are finished

echo "Number of users added = $number_of_users_added" and so on..
 
Old 03-25-2004, 04:33 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
TOTAL=$((TOTAL + 1))
 
Old 03-25-2004, 06:52 PM   #4
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks,but doesn't work

NEW_USERS="/script/userlist"
HOME_BASE="/home/"
number_of_users_added=0
number_of_invalid_users=0

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`" ] && [ ${#USER} -lt 6 ];
then
useradd -g ${GROUP} -p ${PASSWORD} -c ${FULLNAME} -m -d ${HOME_BASE}${USER} ${USER}
let number_of_users_added++

echo "User ${USER} successfully added."

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

Could u write it for me
 
  


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
Easy Bash Script Question skibud2 Linux - Newbie 1 11-17-2004 11:14 AM
Bash: Iterate through $@ (easy++) beatnik007 Programming 2 04-03-2004 01:39 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Easy bash script question TheRealDeal Linux - General 11 08-26-2003 09:45 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 01:19 PM.

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