PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/dialog/samples/copifuncs/copi.ifpoll2

https://bitbucket.org/freebsd/freebsd-head/
Unknown | 107 lines | 89 code | 18 blank | 0 comment | 0 complexity | 0e751c20528911e6ebf4b846c545de04 MD5 | raw file
  1
  2# Packets backup directory - You have to CREATE this directory
  3BAK=/var/spool/ifmail/BAK
  4
  5# logfile of ifcico
  6IFLOG=/var/log/ifmail/sysiflog
  7
  8# log archive
  9IFLOGARC=/var/log/ifmail/TheLog
 10
 11# owner of "ifcico"
 12IFCICO_OWNER=fnet
 13
 14# how often should i try to call NODE?
 15MaxTry=30
 16
 17# delay between outgoing calls in seconds
 18DELAY=10
 19
 20# where to log processing - file or tty/console
 21INFO_TTY=/dev/console
 22
 23# Lets backup the log and use a new one
 24if [ -e $IFLOG ]; then
 25	echo Rearranging logs...
 26	cat $IFLOG >> $IFLOGARC
 27	cp /dev/null $IFLOG
 28fi
 29
 30echo "`date \"+%b %d %T\"` ifpoll[$$]: starting" # >> $INFO_TTY
 31
 32# remember me, not to run as root..
 33#
 34if [ `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
 38fi
 39
 40# argv[1] is the optional node to call
 41#
 42if [ "$1" != "" ]; then
 43	if [ "$1" = "-?" ] || [ "$1" = "-h" ]; then
 44		echo "usage: ifpoll [<node>]"
 45		exit 3
 46	else
 47		NODE=$1
 48	fi
 49fi
 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#
 57i=1; errlv=1
 58while let 'i <= MaxTry' && let 'errlv != 0'
 59do
 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
 75done
 76
 77# if the poll was fine, unpacking..
 78#
 79if [ $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..
 85else
 86	# write me a mail about the failed poll
 87	tail --lines=20 $IFLOG | elm -s "ifpoll: failed" $IFCICO_SYSOP >/dev/null
 88fi
 89
 90echo "`date \"+%b %d %T\"` ifpoll[$$]: finished (rc $errlv)" # >> $INFO_TTY
 91
 92# Collect some infos...
 93echo ""
 94echo "*** Outgoing File Transfer Stats: ***"
 95grep sent $IFLOG
 96echo "*** Incoming File Transfer Stats: ***"
 97grep received $IFLOG
 98echo ""
 99
100echo "---->> New mail: <<-----"
101grep echomail $IFLOG
102echo "---->> Personal mail: <<-----"
103grep "mail from" $IFLOG
104echo ""
105
106# return the errorlevel of ifcico
107exit $errlv