Creating User Accounts from a list in file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Creating User Accounts from a list in file

Shell Programming and Scripting


Tags
linux

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-21-2005
Laila Saif Laila Saif is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 December 2005, 5:07 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Creating User Accounts from a list in file

I have a file that contains a list of names.

I need a loop that creates user accounts to all the names in the list
where username = names in file
password = username

Another question: how can i validate that a particular var is of 6 characters length
I need an if statement that will validate a particular string
if it's less than 6 it will ask the user to reEnter, if it's fine,, it'll procceed..

Please i have to submit it the project today,,
would anyone help me out

Best Regards,
Laila Saif
Sponsored Links
    #2  
Old 12-21-2005
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
 
Join Date: Dec 2005
Last Activity: 22 August 2008, 8:28 AM EDT
Location: London
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
do you want to create a unix user account ??

for the second question :

#!/usr/bin/ksh

if (( ${#var} < 6 ))
then
echo "String length is less than 6"
fi
Sponsored Links
    #3  
Old 12-21-2005
Laila Saif Laila Saif is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 December 2005, 5:07 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,,

Thanx alot for your quick reply..

I'm using Fedora Core 1
using the useradd and passwd commands in shell scripting..

regarding the second question,,,
it works perfectly,, thanx alot,, would i have to change the syntax
if i'm using in a while loop

i need to say

while [ ${#var} < 6 ]
do
echo it must be more than 6 charc.
echo please reEnter
read var
done

but it seems it doesn't work that way,, there's something wrong i don't know what it is,,
    #4  
Old 12-21-2005
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
 
Join Date: Dec 2005
Last Activity: 22 August 2008, 8:28 AM EDT
Location: London
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
printf "Please enter var : "
read var

while (( ${#var} < 6 ))
do
print "$var value is less than 6"
printf "Please reenter var : "
read var
done

Regarding the first question :

if you have many users to add, take any one line of a user from /etc/paswd and format your user file with the same format.. after formating it, copy all the lines from the file and append it to /etc/passwd file in the end through vi and save.

You need to login as root first.

I'm not sure whether they is any other easy way, i generally add user ids in /etc/passwd. I also don't think we can assign the password, we need to run passwd command for each and every user.

Once you complete adding to /etc/passwd, run pwconv command.

Someone can help, if there is a simple way of doing it.
Sponsored Links
    #5  
Old 12-21-2005
Laila Saif Laila Saif is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 December 2005, 5:07 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a million,,

The var testing works fine..

for the first question:

I'm actually which the following menu is part of it:
1. Enter names
2. Creates user accounts.

the first option takes all the names and inputs it in a file called usernames.txt
when option 2 is chosen,, it must create useraccounts for all the names listed in the file
making the useraccount & password = name inserted
it should create a user account for each name that is included in the file automatically from the script..
Sponsored Links
    #6  
Old 12-21-2005
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
 
Join Date: Dec 2005
Last Activity: 22 August 2008, 8:28 AM EDT
Location: London
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not good at linux, may be you can try below stuff

cat users.txt | \
while read userid
do
useradd $userid
done


i hope useradd is not an interactive program. But passwd program needs to be invoked for each and every user to assign password or the users can change their password on first longin.. but not sure whether we have a better solution.
Sponsored Links
    #7  
Old 12-21-2005
Laila Saif Laila Saif is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 23 December 2005, 5:07 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
The command you gave me for the create user is fine, but i need to log on as root
to be able to create those accounts. Do u know whether there's a command that i can use in my script that will allow me to enter as root and create them automatically?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating user accounts vishwaprasad Shell Programming and Scripting 1 07-31-2007 07:13 PM
Creating user accounts Redditt90kg UNIX for Dummies Questions & Answers 0 07-29-2006 09:44 PM
creating user accounts in AIX pdepa UNIX for Advanced & Expert Users 3 01-16-2004 08:59 AM
[LINUX] Creating new user accounts Arendo UNIX for Dummies Questions & Answers 3 11-18-2003 08:45 AM



All times are GMT -4. The time now is 10:56 AM.