LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-06-2004, 10:55 PM   #1
flobadon
LQ Newbie
 
Registered: Oct 2004
Location: Davenport, IA
Distribution: Gentoo 2005.1
Posts: 5

Rep: Reputation: 0
Question Shell Script: Add Users from file


I'm working on a project for one of my classes, and I'm totally new to shell scripts and kind of in shock right now. Anyway, my assignment is to write a simple script that adds users to the system based on usernames and passwords stored in another file (yes, passwords in plaintext - obviously security isn't an issue for the assignment).

I'm stumped on how to get the password assigned correctly. I've tried doing it with useradd -p as well as passwd (normally and by doing something like echo $PASSWORD | passwd --stdin). Apologies if this makes no sense, low on sleep due to finals week. :P

Here is my script thus far:

Code:
#! /bin/bash

#Variables
NEW_USERS="/home/blake/newusers.lst"
HOME_DIR="/home/"

#The script itself...
cat ${NEW_USERS} | \
while read USER PASSWORD
do
  useradd -m -d ${HOME_DIR}${USER} ${USER}
  echo "User $USER has been created"
done
Essentially it's just set up to create a passwordless account for each name in the file "newusers.lst". Any ideas on how I would go about telling it to add a password? I'd like to give a generic password and force users to change it as soon as they login as well.

Thanks!

Blake
 
Old 12-07-2004, 12:28 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Your script is already saving whatever value is in the second column as $PASSWORD. So all you would really need is:

useradd -m -d $HOME_DIR $USER -p $PASSWORD


-twantrd
 
Old 12-07-2004, 03:01 PM   #3
flobadon
LQ Newbie
 
Registered: Oct 2004
Location: Davenport, IA
Distribution: Gentoo 2005.1
Posts: 5

Original Poster
Rep: Reputation: 0
Here's the error I'm getting when I try to pass the -p argument with the ${PASSWORD} variable with the useradd command...

Code:
bash: /home/bconnolly/.bashrc: Permission denied
Would adding something to /etc/skel/.bashrc get rid of this problem? I can login to the accounts created fine if I leave the password bit off, but no dice when I add the password argument to the command...
 
Old 12-07-2004, 03:49 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
From "man useradd"
Code:
       -p passwd
              The encrypted password, as  returned  by  crypt(3).
              The default is to disable the account.

Cheers,
Tink
 
  


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
Shell Script to add samba users dickohead Programming 14 11-18-2016 02:28 AM
Script to add users ssudhi Linux - Newbie 3 05-01-2004 04:33 AM
shell script - add file to archive ? xconspirisist Linux - Software 2 03-20-2004 03:27 PM
Add User Shell Script DAC Programming 2 10-13-2002 03:12 PM
a script that go read the users names in a file and automaticly add then with a commo tumemanques211 Programming 2 03-22-2002 02:13 PM

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

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