| 1 | #! /bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # /usr/bin/gsmsmsrequeue: Re-queues failed SMS |
| 4 | # |
| 5 | # written by Matthias Goebl <[email protected]> |
| 6 | |
| 7 | SPOOLDIR=/var/spool/smsscip-shell filesystem . . `/var/spool/sms`. |
| 8 | PRIORITIES=3 |
| 9 | SMSADMIN=root |
| 10 | SUBJECT="SMS delivery report:" |
| 11 | |
| 12 | send_notifyscip-shell shell shell-project 0.0.0 send_notify().() |
| 13 | { |
| 14 | tmpfile="$SPOOLDIR/tmp/"`basenamescip-shell system . . basename. "$1"` |
| 15 | status="$2" |
| 16 | if mvscip-shell system . . mv. "$1" "$tmpfile" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 17 | # extract the first tab-separated field after the phone number as |
| 18 | # email-address to send the notification to |
| 19 | mailto=` catscip-shell system . . cat. "$tmpfile" | sedscip-shell system . . sed. -ne '1s/^[^ ]* \([^ ]*\).*/\1/p' ` |
| 20 | testscip-shell system . . test. -z "$mailto" && mailto="$SMSADMIN" |
| 21 | catscip-shell system . . cat. "$tmpfile" | mail -s "$SUBJECT $status" "$mailto" |
| 22 | rmscip-shell system . . rm. "$tmpfile" |
| 23 | fi |
| 24 | } |
| 25 | do_accountingscip-shell shell shell-project 0.0.0 do_accounting().() |
| 26 | { |
| 27 | truescip-shell system . . true.; |
| 28 | } |
| 29 | |
| 30 | testscip-shell system . . test. -r /etc/default/gsm-utilsscip-shell filesystem . . `/etc/default/gsm-utils`. && . /etc/default/gsm-utilsscip-shell source . . `/etc/default/gsm-utils`. |
| 31 | |
| 32 | for p in `seqscip-shell system . . seq. 1 $PRIORITIES`; do |
| 33 | lsscip-shell system . . ls. "$SPOOLDIR/failed$p" | while read file; do |
| 34 | if exprscip-shell system . . expr. "$file" : ".*rrrrrrrrrrrr" >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 35 | send_notifyscip-shell shell shell-project 0.0.0 send_notify(). "$SPOOLDIR/failed$p/$file" "failed" |
| 36 | else |
| 37 | # re-queue SMS |
| 38 | mvscip-shell system . . mv. "$SPOOLDIR/failed$p/$file" "$SPOOLDIR/queue$p/${file}r" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 39 | fi |
| 40 | done |
| 41 | done |
| 42 | |
| 43 | for p in `seqscip-shell system . . seq. 1 $PRIORITIES`; do |
| 44 | lsscip-shell system . . ls. "$SPOOLDIR/sent$p" | while read file; do |
| 45 | do_accountingscip-shell shell shell-project 0.0.0 do_accounting(). "$SPOOLDIR/sent$p/$file" "sent" |
| 46 | send_notifyscip-shell shell shell-project 0.0.0 send_notify(). "$SPOOLDIR/sent$p/$file" "sent" |
| 47 | done |
| 48 | done |