#!/bin/sh #---------------------------------------------------------------------------- # sms - send SMS with yaps from postfix and return status report via email # # Version 2006-05-29 by Schlomo Schapiro # # Last Update: $Id: mail2sms 8643 2006-11-14 08:50:47Z jv $ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- phone="$(echo -n "$1" | tr -dc '0123456789' )" sender="${2:-root}" case "$sender" in *@sms*) sender=root ;; esac if [ ${#phone} -lt 11 -o "${phone:0:1}" != 0 ] then logger -p mail.warn -t sms "Invalid phone number $phone from $sender" ( echo "From: smsgate" echo "To: $sender" echo "Subject: ERROR: Invalid phone number $phone" echo "" ) | /usr/sbin/sendmail -oi -t exit fi from="" subject="" message="" while read -r do line="$(echo "$REPLY" | tr -d '\r\n' )" if [ ${#line} -eq 0 -a "$message" = "" ] then message="$from $subject " elif [ "$message" = "" ] then # reading header case "$line" in From:*) from="${line#From: }" ;; Subject:*) subject="${line#Subject: }" ;; esac else message="$message $line" fi done message="${message:0:160}" # truncate to 160 chars msg=$( yaps -v "$phone" "$message" 2>&1 ) if [ $? -eq 0 ] then echo "Sending SMS from $sender to $phone: $message" | logger -p mail.debug -t sms subject="Successfully delivered your SMS to $phone" else subject="ERROR report for failed SMS delivery to $phone" fi ( echo "From: smsgate" echo "To: $sender" echo "Subject: $subject" echo " " echo "SMS message:" echo "$message" echo " " echo "YAPS output:" echo "$msg" ) | /usr/sbin/sendmail -oi -t exit 0