2

I wrote a script that I thought would send input to the terminal when the program request input. I use echo for this.

password=open1234
for I in "a" "b" "c" "d" "e" "f" "g"
do
    passwd ${I}
    echo ${password}
done

This is basically the form of the program. As you can see, i'm trying to change the passwords of multiple users using a script. The problem is that the input from echo never gets sent to the passwd program.

2 Answers 2

2

As written here, you must add --stdin option to passwd.

echo "${password}" | passwd "${I}" --stdin
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, why doesn't echo work? Does it send to stdout insead of stdin?
Echo does work and it prints text to stdout. To connect passwd's stdin and echo's stdout you should pipe it using |.
I tried it, but it doesn't work. All it does is echo the password onto the terminal, but not to the input stream.
1

simply use(It would change all users to the same password):

#!/bin/bash
script='
passwd $user <<PASS
open1234
open1234
PASS
'
for user in $(cat user.txt)
do
   $script
done

1 Comment

Thanks. I looked at the reference and found out why it is used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.