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
  • 71,025
  • 22
  • 98
  • 142
jax
  • 696
  • 11
  • 29

2 Answers2

2

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

echo "${password}" | passwd "${I}" --stdin
Community
  • 1
  • 1
loentar
  • 4,971
  • 1
  • 21
  • 24
  • 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,584
  • 7
  • 49
  • 85