]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/dialog/samples/copifuncs/copi.ifpoll2
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / dialog / samples / copifuncs / copi.ifpoll2
1
2 # Packets backup directory - You have to CREATE this directory
3 BAK=/var/spool/ifmail/BAK
4
5 # logfile of ifcico
6 IFLOG=/var/log/ifmail/sysiflog
7
8 # log archive
9 IFLOGARC=/var/log/ifmail/TheLog
10
11 # owner of "ifcico"
12 IFCICO_OWNER=fnet
13
14 # how often should i try to call NODE?
15 MaxTry=30
16
17 # delay between outgoing calls in seconds
18 DELAY=10
19
20 # where to log processing - file or tty/console
21 INFO_TTY=/dev/console
22
23 # Lets backup the log and use a new one
24 if [ -e $IFLOG ]; then
25         echo Rearranging logs...
26         cat $IFLOG >> $IFLOGARC
27         cp /dev/null $IFLOG
28 fi
29
30 echo "`date \"+%b %d %T\"` ifpoll[$$]: starting" # >> $INFO_TTY
31
32 # remember me, not to run as root..
33 #
34 if [ `whoami` != "$IFCICO_OWNER" ]; then
35         echo "*** run $0 as the owner of ifcico ***"
36         echo "`date \"+%b %d %T\"` ifpoll[$$]: wrong uid (rc 2)" # >> $INFO_TTY
37         exit 2
38 fi
39
40 # argv[1] is the optional node to call
41 #
42 if [ "$1" != "" ]; then
43         if [ "$1" = "-?" ] || [ "$1" = "-h" ]; then
44                 echo "usage: ifpoll [<node>]"
45                 exit 3
46         else
47                 NODE=$1
48         fi
49 fi
50
51 # let's pack the fido stuff..
52 #
53 $FIDOPATH/ifpack
54
55 # loop until ifcico could connect the node or MaxTry is encountered
56 #
57 i=1; errlv=1
58 while let 'i <= MaxTry' && let 'errlv != 0'
59 do
60         echo -n "`date \"+%b %d %T\"` ifpoll[$$]: $i. try ($NODE) " # >> $INFO_TTY
61         #
62         # start ifcico in master mode ..
63         #
64         $FIDOPATH/ifcico -r 1 $NODE
65         errlv=$?
66         if [ $errlv != "0" ]; then
67                 echo "failed" # >> $INFO_TTY
68                 if [ $i != $MaxTry ]; then
69                         sleep $DELAY
70                 fi
71                 let i=i+1
72         else
73                 echo "ok :)" # >> $INFO_TTY
74         fi
75 done
76
77 # if the poll was fine, unpacking..
78 #
79 if [ $errlv = "0" ]; then
80         echo "`date \"+%b %d %T\"` ifpoll[$$]: unpacking.. " # >> $INFO_TTY
81         cp -f /var/spool/ifmail/inb/*.* $BAK
82         $FIDOPATH/ifunpack
83         # add here some additional lines for processing tic files or
84         # incoming file-lists or simular..
85 else
86         # write me a mail about the failed poll
87         tail --lines=20 $IFLOG | elm -s "ifpoll: failed" $IFCICO_SYSOP >/dev/null
88 fi
89
90 echo "`date \"+%b %d %T\"` ifpoll[$$]: finished (rc $errlv)" # >> $INFO_TTY
91
92 # Collect some infos...
93 echo ""
94 echo "*** Outgoing File Transfer Stats: ***"
95 grep sent $IFLOG
96 echo "*** Incoming File Transfer Stats: ***"
97 grep received $IFLOG
98 echo ""
99
100 echo "---->> New mail: <<-----"
101 grep echomail $IFLOG
102 echo "---->> Personal mail: <<-----"
103 grep "mail from" $IFLOG
104 echo ""
105
106 # return the errorlevel of ifcico
107 exit $errlv