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

user1:[email protected]
user2:[email protected]
user3:[email protected]

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

Manu Old post

1 Answer 1


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
    Commented Jan 6, 2017 at 20:10
  • Updated the answer for multi lines in email body. Commented Jan 6, 2017 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .