Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:linux:scripted_email [2014/11/15 09:13]
tech:linux:scripted_email [2014/11/15 09:13] (current)
Line 1: Line 1:
 +====== Scripted Email ======
 +Used to send email to list of people from flat file.  Usually when sending from server you want the reply-to set correctly so the replies go to a proper email account.
  
 +===== Input File =====
 +The input file is cre.txt and has the following format
 +  * Header: Username Password Email
 +  * Rows: userid password email
 +  * Fields are space delimited
 +
 +Sample file
 +<​code>​
 +Username Password Email
 +hjames N8dseRzx8l someone1@example.org
 +itom 08sdfssRPd someone2@example.org
 +klucy 1eh4g6y88 someone3@example.org
 +</​code>​
 +===== Updates to script =====
 +Things to update in script are
 +  * input file location (input)
 +  * Subject (subject1)
 +  * Body as appropriate
 +  * replyto field
 +
 +===== Code =====
 +The tr command is optional. ​ In case the file arrived from DOS/WINDOWS it may have funny characters
 +<code bash>
 +#!/bin/bash
 +cat cre.txt | tr -d '​\015'​ > cre1.txt
 +input=cre1.txt
 +subject1="​Some Subject"​
 +while read -r line
 +do
 +    IFS=" " read -r f1 f2 f3 <<<"​$line"​
 +    if [ ! $f1 = "​Username"​ ]; then
 +        echo "​Emailing $f3 ..."
 +        body1="​You Userid is $f1 and Password is $f2"
 +        echo $body1 | mailx -s "​$subject1"​ -S replyto=someuser@example.com "​$f3"​
 +    fi
 +done <"​$input"​
 +</​code>​
 +
 +===== Keywords =====
 +for loop mass

QR Code
QR Code tech:linux:scripted_email (generated for current page)