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