LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-23-2004, 08:27 PM   #1
yulitao
LQ Newbie
 
Registered: Mar 2004
Posts: 18

Rep: Reputation: 0
Bash sciprt question, how to do this????


This is my script

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."
else
echo "The user has existed"

fi

everything is working fine, now the format of userlist is
USER PASSWORD GROUP FULLNAME
john01 mypass business JOHN

So if I just want to username has no more than 6 characters, password must be over 8 characters, Group just can be "business" or "operation" or "marketing", otherwise the user information is invalid and can't be allowed to add in linux system, and shows "user invaild"information. but now even I input username like john23323e2323403222332, it still be added, so how should I do! Please!

Last edited by yulitao; 03-23-2004 at 08:30 PM.
 
Old 03-24-2004, 09:05 AM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
You can get the length of a variable using this format

${#MYVARIABLE}

so I guess you could do

Code:
#!/bin/bash

USERNAME="john123456789"

if [ ${#USERNAME} -gt 6 ]; then
  echo "UserName is too long"
else
  echo "Okay, Length of USERNAME is ${#USERNAME}"
fi
I'd test for zero length aswell just incase
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash question lnxduck Programming 3 09-30-2005 08:50 AM
Yet another bash question. pete1234 Programming 3 09-25-2005 03:22 PM
Sciprt deciding icon apperence jnusa Linux - Software 0 01-06-2005 07:07 AM
bash question shanenin Linux - Software 3 02-14-2004 06:10 PM
BASH question cxel91a Programming 6 12-31-2003 03:42 AM

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

All times are GMT -5. The time now is 02:41 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