[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

piping input to passwd

Posted on 1998-09-17
2
Medium Priority
?
1,080 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
marcelofr earned 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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 …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

649 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