LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-12-2009, 09:40 PM   #1
redleg7
LQ Newbie
 
Registered: May 2008
Posts: 5

Rep: Reputation: 0
Question Script passwd command by reading passwords from a file


I am attempting to create users by writing a perl script which opens and reads a file line by line. A typical line consists of logon|fullName|password. I am able to create the user account as expected. However, the passwd command does not set the password correctly since it requires the password to be re-entered. Here is the code that I am using:

sub createUser
{
my($logon, $fullName, $password)=@_;
my $useradd = `useradd -c "$fullName" $logon`;
my $setPasswd = `echo $password | /usr/bin/passwd --stdin $logon`;
}

Specificially, the set password part does not seem to work without my interaction.

Last edited by redleg7; 01-12-2009 at 09:42 PM.
 
Old 01-12-2009, 09:57 PM   #2
BinWondrin
Member
 
Registered: Jun 2008
Distribution: Fedora, RHEL, Ubuntu
Posts: 33

Rep: Reputation: 15
This is how you can do it in bash without being prompted to do it again.

Code:
passwd --stdin < passwordfile username
e.g.:
Code:
passwd --stdin < pswdfile thomas
You would have to create a temporary file called pswdfile and the remove it.

Since you are writing this in perl you would have to make those lines into system calls.

BW
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking passwords against the linux /etc/passwd file sleepy0110 Programming 2 09-29-2008 10:05 PM
read command in shell script what to do for reading a particular char Ashok_mittal Linux - Newbie 11 01-21-2008 05:01 AM
Shell script to list all users in /etc/passwd file milestone Programming 6 09-15-2007 12:57 PM
Reading the passwd passwords BoldKiller Programming 2 05-21-2004 11:07 PM
Script, Reading a file, When end of file? elibm Programming 2 07-16-2001 11:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:50 AM.

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