#!/bin/bash
if [ $# -lt 2 ]; then
echo "No arguments passed! I need a 'mailaddr;subject' .csv and a txt containing the fixed message."
echo "csvmailer.sh addresses.csv message.txt"
exit 1
fi
while read p; do
IFS=';'
TOKENS=($p)
EMAIL=${TOKENS[0]}
SUBJ=${TOKENS[1]}
IFS=' '
mail -s "$SUBJ" "$EMAIL" < $2
done < $1
The CSV is like "jane.doe@company.com;This is a message in the subject about deleting the account of 'johndoe@company.com'\n". Do NOT put a semicolon into the subject column :-D
IFS sets the Internal Field Separator to semicolon (';'), instead of the default whitespace. This way the array generator/tokenizer is dead simple in the next line.
$1 is the CSV file, read into $p line-by-line.
$2 is the fixed message piped into mail.
No comments :
Post a Comment