~ubuntu-branches/debian/jessie/gsmlib/jessie

« back to all changes in this revision

Viewing changes to contrib/gsmsmsrequeue

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2006-05-20 21:54:42 UTC
  • mfrom: (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060520215442-nb9iiu95mzkqfejf
Tags: 1.10-10
FTBFS with G++ 4.1: extra qualifications (Closes: #356109)

Show diffs side-by-side

added added

removed removed

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