Solved

piping input to passwd

Posted on 1998-09-17
2
1,035 Views
Last Modified: 2012-08-14
I'm using Redhat 5.1.
I want to set a user's password from a shell script without and human intervention.

I have tried this (and various others):

echo -e "foo123\nfoo123" | passwd foobar

But I get this:
New UNIX password: Retype new UNIX password:
New UNIX password:
New UNIX password:
passwd: Conversation error

Any ideas?

Many Thanks!

0
Comment
Question by:mag062397
2 Comments
 
LVL 3

Accepted Solution

by:
marcelofr earned 50 total points
ID: 1638062
passwd command reads from the tty DIRECTLY, not from stdin so you need at least a pseudo tty. The following expect script may help you:

#!/usr/bin/expect
set oldpass [lindex $argv 0]
set newpass [lindex $argv 1]
spawn /usr/bin/passwd
expect word:
sleep 1
send $oldpass\r
expect word:
sleep 1
send $newpass\r
expect word:
sleep 1
send $newpass\r

Put this stuff in a script, chmod +x it and call it passing old and new passwords as parameters.

Good Luck
0
 

Author Comment

by:mag062397
ID: 1638063
Thank you I got it working.  The only thing I had to add was either a "sleep 1" or an "expect success" at the end of the script.  For some reason the script would end and I think the passwd program would think it was killed or something so it would not make the change.  By putting in one more expect string the script waits until passwd completes its task.  A sleep 1 also worked; however I'm going to stick with the expect success.

Thanks again.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question