How can I pipe some input using echo
, into program that requires user typing something two times?
for example
echo "somepassword"|passwd someuser
creates this error message
Enter new UNIX password: Retype new UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged
because I didn't retyped password
passwd --stdin <username> This command will read from the echo command and pass it to the passwd command. So this will set the user1 password to userpasswd1.
#!/bin/bash password="" echo "Enter Username : " # it will read username read username pass_var="Enter Password :" # this will take password letter by letter while IFS= read -p "$pass_var" -r -s -n 1 letter do # if you press enter then the condition # is true and it exit the loop if [[ $letter == $'\0' ]] then break fi ...
You need to send the password twice:
(echo 'somepassword'; echo 'somepassword') | passwd someuser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With