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