Message format is:
To: one recipient
To: another recipient
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary
Text body.
To: another recipient
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary
Text body.
#!/bin/bash
# Sample script to allow multiple recipients in one message file.
# Define this script as a checkhandler.
outgoing="/var/spool/sms/outgoing"
recipients=`formail -zx "To:" < "$1"`
#count=`echo "$recipients" | wc -l`
count=`echo "$recipients" | wc -w`
if [ $count -gt 1 ]; then
# Will need echo which accepts -n argument:
ECHO=echo
case `uname` in
SunOS)
ECHO=/usr/ucb/echo
;;
esac
messagebody=`sed -e '1,/^$/ d' < "$1"`
headers=`formail -X "" -I "To:" -f < "$1"`
for recipient in $recipients
do
file=`mktemp $outgoing/send_XXXXXX`
$ECHO "To: $recipient" > $file
if [ "x$headers" != "x" ]; then
$ECHO "$headers" >> $file
fi
$ECHO "" >> $file
$ECHO -n "$messagebody" >> $file
done
# Remove processed file:
rm $1
# Tell to smsd that checkhandler has spooled this message:
exit 2
fi
exit 0
# Sample script to allow multiple recipients in one message file.
# Define this script as a checkhandler.
outgoing="/var/spool/sms/outgoing"
recipients=`formail -zx "To:" < "$1"`
#count=`echo "$recipients" | wc -l`
count=`echo "$recipients" | wc -w`
if [ $count -gt 1 ]; then
# Will need echo which accepts -n argument:
ECHO=echo
case `uname` in
SunOS)
ECHO=/usr/ucb/echo
;;
esac
messagebody=`sed -e '1,/^$/ d' < "$1"`
headers=`formail -X "" -I "To:" -f < "$1"`
for recipient in $recipients
do
file=`mktemp $outgoing/send_XXXXXX`
$ECHO "To: $recipient" > $file
if [ "x$headers" != "x" ]; then
$ECHO "$headers" >> $file
fi
$ECHO "" >> $file
$ECHO -n "$messagebody" >> $file
done
# Remove processed file:
rm $1
# Tell to smsd that checkhandler has spooled this message:
exit 2
fi
exit 0
EDIT: After changing wc -l to wc -w, the script allows multiple numbers in To: field (separated with spaces) and also multiple To: fields as before:
To: 358400111111 358400222222 358400333333
To: 358400444444
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary
Text body.
To: 358400444444
To: Etc. ( number of To: headers is not limited. )
Other_headers: if necessary
Text body.
« Last edit by keke on Mon Dec 13, 2010 11:34, 169 months ago. »