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.

jaypal singh
  • 74,723
  • 23
  • 102
  • 147
jax
  • 728
  • 1
  • 11
  • 31

2 Answers2

2

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

echo "${password}" | passwd "${I}" --stdin
Community
  • 1
  • 1
loentar
  • 5,111
  • 1
  • 24
  • 25
  • Thanks, why doesn't echo work? Does it send to stdout insead of stdin? – jax Feb 19 '14 at 11:40
  • Echo does work and it prints text to stdout. To connect passwd's stdin and echo's stdout you should pipe it using `|`. – loentar Feb 19 '14 at 13:16
  • I tried it, but it doesn't work. All it does is echo the password onto the terminal, but not to the input stream. – jax Feb 19 '14 at 22:21
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
MLSC
  • 5,872
  • 8
  • 55
  • 89