Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-06-2006, 07:48 PM   #1
Registered: Aug 2004
Location: Arroyo Grande, Ca
Distribution: Ubuntu 6.06
Posts: 49

Rep: Reputation: 15
Bash script passwd help

I wrote a script to add users to my server. it's very simple and just sets them up with a home/public_html dir, etc. i want to check to make sure the passwords entered are the same, else exit the script. but my question is: how can i take two variables and fee them into the passwd command (or just as a new user is being made)

if [ "$pass1" = "$pass2" ]; then

  echo "Passwords match... adding user to system."
  echo $pass1; echo $pass2 | adduser $name --force-badname
it's the third line that gives me trouble.
this is the ouput i get:

Passwords match... adding user to system.
Adding user `jacob'...
Adding new group `jacob' (1011).
Adding new user `jacob' (1011) with group `jacob'.
Creating home directory `/home/jacob'.
Copying files from `/etc/skel'
Enter new UNIX password: Retype new UNIX password: Sorry, passwords do not match
passwd: Authentication information cannot be recovered
adduser: `/usr/bin/passwd jacob' returned error code 10.  Aborting.
any suggestions?
Old 08-06-2006, 08:12 PM   #2
Registered: Dec 2004
Distribution: Gentoo
Posts: 44

Rep: Reputation: 15
echo password | passwd --stdin username

(Your version of passwd may not support --stdin option), in that case you may have to use useradd -p option but remember you have to pass the output of base64 encoded crypt($pass) function result as the parameter value of -p, which I don't know how to do from BASH.
Old 08-07-2006, 02:03 AM   #3
spirit receiver
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
You could also write an Expect script that feeds the adduser command with input, but that's a little awkward. See "man expect".


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
Delete group users from /etc/passwd SCRIPT wesleywest Linux - General 5 03-08-2005 09:59 AM
Looking for addusesr&passwd shell script szklanka Programming 1 02-22-2005 08:37 PM
need a script that can change the passwd bahadur Linux - Security 1 07-09-2004 05:07 AM
Bash script to edit passwd without Root password? NetFlash Linux - Newbie 2 11-29-2003 04:22 PM
bash script for passwd mystykmax Programming 2 02-20-2003 12:33 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration