LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools Search this Thread
Old 01-12-2009, 10:40 PM   #1
redleg7
LQ Newbie
 
Registered: May 2008
Posts: 5
Thanked: 0
Question Script passwd command by reading passwords from a file


[Log in to get rid of this advertisement]
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 10:42 PM..
redleg7 is offline     Reply With Quote
Old 01-12-2009, 10:57 PM   #2
BinWondrin
LQ Newbie
 
Registered: Jun 2008
Distribution: Fedora, RHEL, Ubuntu
Posts: 23
Thanked: 0
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
BinWondrin is offline     Reply With Quote

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
checking passwords against the linux /etc/passwd file sleepy0110 Programming 2 09-29-2008 11:05 PM
read command in shell script what to do for reading a particular char Ashok_mittal Linux - Newbie 11 01-21-2008 06:01 AM
Shell script to list all users in /etc/passwd file milestone Programming 6 09-15-2007 01:57 PM
Reading the passwd passwords BoldKiller Programming 2 05-22-2004 12:07 AM
Script, Reading a file, When end of file? elibm Programming 2 07-16-2001 12:01 PM


All times are GMT -5. The time now is 04:31 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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration