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


Tags
cron, linux, password, script, sh

Closed    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 01-06-2017
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 September 2017, 5:42 PM EDT
Location: Saskatchewan
Posts: 22,417
Thanks: 1,126
Thanked 4,237 Times in 3,917 Posts
Quote:
Originally Posted by Manu_H View Post
I found another way..
How would this be (security`?)


Code:
#!/bin/bash
>tmp.txt
join -t: cleartext.txt maillist.txt | while read line
do
  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
done

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
Code:
"Hello
World"

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.


Code:
join -t: cleartext.txt maillist.txt | while IFS=":" read -r USERID PSWD EMAILID
do
  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
EOF
done


Last edited by Corona688; 01-06-2017 at 05:00 PM..
Sponsored Links
    #9  
Old Unix and Linux 01-06-2017
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
Closed

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 05:03 PM
Script for count files and send mails atrailm Shell Programming and Scripting 2 12-12-2012 11:20 AM
Generate list of deleted files eshwaconsulting UNIX for Dummies Questions & Answers 1 02-01-2012 12:13 PM
Script to consolidate files as mails,groupid manish123456 Shell Programming and Scripting 7 08-31-2010 09:12 PM
how to generate a list of files jasongr Shell Programming and Scripting 3 12-13-2005 07:15 AM



All times are GMT -4. The time now is 05:56 AM.