i am using a script to create a random password for a user.
The file looks like


Passwords are openssl passwd hashed. I have an own file where the password is written in cleartext.
No i want to send an E-Mail to the users with the new password.
I have a file (maillist.txt) with


Now i want to generate an E-Mail to user1.
This should generate an E-Mail to mail@domain1.tld, containing the username (user1) and the password (password1). I want to do it with mailx.
Can you please help me?

Manu Old post


Try the following:

join -t: cleartext.txt maillist.txt | awk -F: '{ print "echo Username: "$1" Passwd: "$2" | mailx -s Information "$3 }' |sh

If multi lines are required in the email body, refer below

join -t: cleartext.txt maillist.txt | while read line
  echo $line
  USER=$(echo $line | awk -F: '{ print $1 }')
  PSWD=$(echo $line | awk -F: '{ print $2 }')
  EMAILID=$(echo $line | awk -F: '{ print $3 }')
  echo "Hello $(echo $USER | tr a-z A-Z), your password has been changed!!!<br>" >tmp.txt
  echo "<b>Username</b>: $USER<br>" >>tmp.txt
  echo "<b>Password</b>: $PSWD<br>" >> tmp.txt
  cat tmp.txt | mailx -s "$(echo -e 'Password Changed!!!\nContent-Type: text/html')" $EMAILID

  • Is it possible to add something to the text? Something like "Hello your password has been changed" and something after the text? If i do { print "echo Blablabla \n test Username: ...} i get an unexpected error? – Manu_H Jan 6 '17 at 20:10
  • Updated the answer for multi lines in email body. – sureshraju Jan 6 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.