Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Generate E-Mails with content on different files

Shell Programming and Scripting

cron, linux, password, script, sh

Thread Tools Search this Thread Display Modes
Old Unix and Linux 01-06-2017   -   Original Discussion by Manu_H
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 21 November 2017, 3:22 PM EST
Location: Saskatchewan
Posts: 22,518
Thanks: 1,154
Thanked 4,273 Times in 3,946 Posts
Originally Posted by Manu_H View Post
I found another way..
How would this be (security`?)

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

USER is a special variable and should not have its value changed. Try something else, like USERID.

I think an HTML email is a bad idea as any < > & in passwords are liable to be eaten. You can work around that but it would be a lot of processing. (That's also the reason for read -r, incidentally - to prevent backslashes from being eaten.)

You don't need echo to put two lines into a variable. Just put a real newline inside the "" and it will contain a real newline, like

but again I don't think an HTML email is a good idea unless you want to get really fancy.

Most of that can be stripped down back into what I just gave you -- there's no need for all those awk's.

If your mailx supports -r, you can set the From: address. If it doesn't support -r, you can try mailx -a "From: Foo Bar <foo.bar@someplace.com>" ...

Otherwise, you may be out of luck.

join -t: cleartext.txt maillist.txt | while IFS=":" read -r USERID PSWD EMAILID
  echo $line
  mailx -r "my@email.com" -s "Password Changed!"  $EMAILID <<EOF
Hello $(echo $USERID | tr 'a-z' 'A-Z'), your password has been changed!
Username: $USERID
Password: $PSWD

Last edited by Corona688; 01-06-2017 at 06:00 PM..
Sponsored Links
Old Unix and Linux 01-06-2017   -   Original Discussion by Manu_H
Manu_H Manu_H is offline
Registered User
Join Date: Jan 2017
Last Activity: 6 January 2017, 4:48 PM EST
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Okay thank you a lot.
I will use your last Code - thats perfect! Linux
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Merge files and generate a resume in two files jiam912 Shell Programming and Scripting 14 12-04-2013 06:03 PM
Script for count files and send mails atrailm Shell Programming and Scripting 2 12-12-2012 12:20 PM
Generate list of deleted files eshwaconsulting UNIX for Dummies Questions & Answers 1 02-01-2012 01:13 PM
Script to consolidate files as mails,groupid manish123456 Shell Programming and Scripting 7 08-31-2010 10:12 PM
how to generate a list of files jasongr Shell Programming and Scripting 3 12-13-2005 08:15 AM

All times are GMT -4. The time now is 06:50 AM.