no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | tech:linux:scripted_email [2014/11/15 15:13] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| 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 | ||
| + | < | ||
| + | Username Password Email | ||
| + | hjames N8dseRzx8l someone1@example.org | ||
| + | itom 08sdfssRPd someone2@example.org | ||
| + | klucy 1eh4g6y88 someone3@example.org | ||
| + | </ | ||
| + | ===== 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. | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | cat cre.txt | tr -d ' | ||
| + | input=cre1.txt | ||
| + | subject1=" | ||
| + | while read -r line | ||
| + | do | ||
| + | IFS=" " read -r f1 f2 f3 <<<" | ||
| + | if [ ! $f1 = " | ||
| + | echo " | ||
| + | body1=" | ||
| + | echo $body1 | mailx -s " | ||
| + | fi | ||
| + | done <" | ||
| + | </ | ||
| + | |||
| + | ===== Keywords ===== | ||
| + | for loop mass | ||