Solved

piping input to passwd

Posted on 1998-09-17
2
1,024 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now