/cron.daily/popularity-contest

http://github.com/brinkman83/bashrc · Shell · 96 lines · 69 code · 17 blank · 10 comment · 22 complexity · e5712443c40fa3780de7ae77692caeb7 MD5 · raw file

  1. #!/bin/sh
  2. # don't run if this package is removed but not purged
  3. if [ ! -f /usr/sbin/popularity-contest ]; then
  4. exit 0
  5. fi
  6. unset MAILFROM
  7. unset MAILTO
  8. unset MY_HOSTID
  9. unset PARTICIPATE
  10. unset SUBMITURLS
  11. unset USEHTTP
  12. # get configuration information
  13. . /usr/share/popularity-contest/default.conf
  14. . /etc/popularity-contest.conf
  15. # don't run if MAILTO address is blank, and not configured to use HTTP POST!
  16. if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi
  17. # don't run if PARTICIPATE is "no" or unset!
  18. [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0
  19. if [ -n "$HTTP_PROXY" ]; then
  20. export http_proxy="$HTTP_PROXY";
  21. fi
  22. # Only run on the given day, to spread the load on the server a bit
  23. if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
  24. exit 0
  25. fi
  26. # keep old logs
  27. cd /var/log
  28. umask 022
  29. savelog -c 7 popularity-contest >/dev/null
  30. POPCON=/var/log/popularity-contest
  31. run_popcon()
  32. {
  33. su -s /bin/sh -c "/usr/sbin/popularity-contest" nobody
  34. }
  35. do_sendmail()
  36. {
  37. if [ -n "$MAILFROM" ]; then
  38. sendmail -oi -f "$MAILFROM" $MAILTO
  39. else
  40. sendmail -oi $MAILTO
  41. fi
  42. }
  43. # generate the popularity contest data
  44. run_popcon > $POPCON
  45. SUBMITTED=no
  46. # try to post the report through http POST
  47. if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
  48. for URL in $SUBMITURLS ; do
  49. if setsid /usr/share/popularity-contest/popcon-upload \
  50. -u $URL -f $POPCON -C 2>/dev/null ; then
  51. SUBMITTED=yes
  52. else
  53. logger -t popularity-contest "unable to submit report to $URL."
  54. fi
  55. done
  56. fi
  57. # try to email the popularity contest data
  58. if [ yes != "$SUBMITTED" ] && [ -n "$MAILTO" ]; then
  59. if [ -x "`which sendmail 2>/dev/null`" ]; then
  60. (
  61. if [ -n "$MAILFROM" ]; then
  62. echo "From: <$MAILFROM>"
  63. echo "Sender: <$MAILFROM>"
  64. fi
  65. echo "To: $MAILTO"
  66. echo "Subject: popularity-contest submission"
  67. echo "MIME-Version: 1.0"
  68. echo "Content-Type: text/plain"
  69. echo
  70. cat $POPCON
  71. ) | do_sendmail
  72. SUBMITTED=yes
  73. else
  74. logger -t popularity-contest "unable to submit report using sendmail."
  75. fi
  76. fi
  77. if [ "yes" != "$SUBMITTED" ] ; then
  78. logger -t popularity-contest "unable to submit report."
  79. fi