mailnotify
is called by a background process at regular intervals. The script sends an automated e-mail to subscribed users if topics were changed in a web since the script was last run.
%NOTIFYTOPIC%
*
subscriber [ :
topics ]
Where subscriber can be a WikiName, an E-mail address, or a
group name. If subscriber contains any characters that are not legal in
an email address, then it must be enclosed in 'single' or "double" quotes.
topics is an optional space-separated list of topics:
*
in a topic name, where it is treated as a wildcard character*
will match zero or more other characters - so, for example, Fred*
will match all topic names starting with Fred
, *Fred
will match all topic names ending with Fred
, and *
will match all topic names.
* daisy.cutter@flowers.comSubscribe Daisy to all changes to topics that start with
Web
.
* daisy.cutter@flowers.com : Web*Subscribe Daisy to changes to topics starting with
Petal
, and their immediate children, WeedKillers and children to a depth of 3, and all topics that match start with Pretty
and end with Flowers
e.g. PrettyPinkFlowers
* DaisyCutter: Petal* (1) WeedKillers (3) Pretty*FlowersSubscribe StarTrekFan to changes to all topics that start with
Star
except those that end in Wars
, sInTheirEyes
or shipTroopers
.
* StarTrekFan: Star* - *Wars - *sInTheirEyes - *shipTroopersSubscribe Daisy to the full content of NewsLetter whenever it has changed
* daisy@flowers.com: NewsLetter?Subscribe buttercup to NewsLetter and its immediate children, even if it hasn't changed.
* buttercup@flowers.com: NewsLetter! (1)Subscribe GardenGroup (which includes Petunia) to all changed topics under AllnewsLetters to a depth of 3. Then unsubscribe Petunia from the ManureNewsLetter, which she would normally get as a member of GardenGroup:
* GardenGroup: AllNewsLetters? (3) * petunia@flowers.com: - ManureNewsLetterSubscribe
IT:admins
(a non-TWiki group defined by an alternate user mapping) to all changes to Web* topics.
* 'IT:admins' : Web*A user may be listed many times in the WebNotify topic. Where a user has several lines in WebNotify that all match the same topic, they will only be notified about changes that topic once (though they will still receive individual mails for news topics). If a group is listed for notification, the group will be recursively expanded to the e-mail addresses of all members.
{MailerContrib}{EmailFilterIn} setting in =configure
.
%USERSWEB%
instead of Main
, but this is not necessary even if you have renamed the main web by configuring {MainWebName}
in configure.
SEARCH
. The number of topics listed by the limit
parameter.:
%SEARCH{ ".*" web="TWiki" type="regex" nosearch="on" sort="modified" reverse="on" limit="50" }%
%SEARCH{}%
.
SEARCH
:
%SEARCH{ "\.*" scope="topic" type="regex" nosearch="on" }%
%STATISTICSTOPIC%
TWiki also generates overall site usage statistics in Main.SiteStatistics (do not create that page, it is created automatically based on SiteStatisticsTemplate). On a monthly basis, the following items are recorded using system data and TWiki log data across all webs: Number of webs, number of topics, number of attachments, number of topic views, number of topic updates, number of files uploads, data size, pub size, disk use, number of users, number of groups, number of plugins installed compared to total number of plugins available, and the 10 top contributors.
{Log}{view}
, {Log}{save}
and {Log}{upload}
are set in configure. This will generate log file entries (see below).
twiki/bin/statistics
script from a cron job - once a day is recommended. This will update the SiteStatistics and the WebStatistics topics in all webs.
nobody
or www-data
. Example crontab entry: 0 0 * * * (cd /path/to/twiki/bin; ./statistics >/dev/null 2>&1)
nobody
: Run the utility twiki/tools/geturl.pl
in your cron job and specify the URL of the twiki/bin/statistics
script as a parameter. Example: 0 0 * * * (cd /path/to/twiki/tools; ./geturl.pl mydomain.com /urlpath/to/twiki/bin/statistics >/dev/null 2>&1)
geturl.pl
will do a TWiki CGI request as the TWikiGuest user, so if you use this workaround, the WebStatistics topics you are updating will have to be writable by TWikiGuest.
cd twiki/bin; ./statistics -logdate 2011-05 -webs TWiki,Sandbox
twiki/bin/statistics
script can also be executed as a CGI script - just enter the URL in your browser. Examples: /cgi-bin/statistics
/cgi-bin/statistics/Main
/cgi-bin/statistics/Main?logdate=2025-04
/cgi-bin/statistics?logdate=2025-04;webs=ProjectX,ProjectY,ProjectZ
log<year><month>.txt
twiki/logs/log202504.txt
| <time in GMT> | <wikiusername> | <action> | <web>.<topic> | <extra info> | <IP address> |
| 30 Apr 2025 - 19:41 | Main.TWikiGuest | view | TWiki06x01.WebRss | | 66.124.232.02 |
Script | Action name | Extra info |
---|---|---|
attach | attach | when viewing attach screen of previous uploaded attachment: filename |
changes | changes | |
edit | edit | when editing non-existing topic: (not exist) |
login, logon, attach, edit, register, rest, view, vewfile | sudologin , sudologout | Login name of administrator user who is logging in or out |
manage | changepasswd | Login name of user who's password is changed |
mdrepo | mdrepo | operation and its arguments |
rdiff | rdiff | higher and lower revision numbers: 4 3 |
register | regstart | WikiUserName, e-Mail address, LoginName: user attempts to register |
register | register | E-mail address: user successfully registers |
register | bulkregister | WikiUserName of new, e-mail address, admin ID |
rename | rename | when moving topic: moved to Newweb.NewTopic |
rename | renameweb | when renaming a web: moved to Newweb |
rename | move | when moving attachment: Attachment filename moved to Newweb.NewTopic |
resetpasswd | resetpasswd | Login name of user who's password is reset |
save | save | when replacing existing revision: repRev 3 when user checks the minor changes box: dontNotify when user changes attributes to an exising attachment: filename.ext |
save | cmd | special admin parameter used when saving |
search | search | search string |
upload | upload | filename |
view | view | when viewing non-existing topic: (not exist) when viewing previous topic revision: r3 |
viewfile | viewfile | Attachment name and revision: File.txt, r3 |
Net::SMTP
module if it is installed on your system. Set this with the {SMTP}{MAILHOST}
setting in configure.
{SMTP}{SENDERHOST}
configure setting to set the mail sender host - some SMTP installations require this.
$ sudo setsebool -P httpd_can_sendmail on
$ sudo setsebool -P httpd_can_network_connect on
sendmail
, if the Net::SMTP
module is not installed or not functioning properly. Set the program path in {MailProgram}
and set {SMTP}{MAILHOST}
to an empty value in configure.
The notify e-mail uses the default changes.tmpl
template, or a skin if activated in the TWikiPreferences.
mailnotify also relies on two hidden files in each twiki/data/Web
directory: .changes
and .mailnotify.
Make sure both are writable by your web server process. .changes
contains a list of changes; go ahead and make this empty. .mailnotify
contains a timestamp of the last time notification was done.
cron
table so that mailnotify
is called in an interval of your choice. Please consult man crontab
of how to modify the table that schedules program execution at certain intervals. Example:
% crontab -e 0 1 * * * (cd /path/to/twiki; perl -I bin tools/mailnotify -q)The above line will run mailnotify nightly at 01:00. The
-q
switch suppresses all normal output. Details at MailerContrib.
For ISP installations: Many ISPs don't allow hosted accounts direct cron access, as it's often used for things that can heavily load the server. Workaround scripts are available.
On Windows: You can use a scheduled task if you have administrative privileges. TWiki:Codev/CronTabWinmailnotify
script to limit the webs to be handled. So you can add an additional crontab entries with a different schedule for each web. Is it included in the core? PeterKlausner submitted patch 23 Oct 2002
-- PeterMasiar - 02 Jun 2003
It might be appropriate to have references to some of the notification features
that are not (yet?) part of the standard TWiki distribution
- such as ImmediateNotifyPlugin.
Or RSS. Or News.
And %MAILLINKTO%.
I.e. the general issue is of interaction of TWiki with notification systems.
-- AndyGlew - 24 Jun 2003
>For ISP installations: Many ISPs don't allow hosted accounts direct cron access, as it's often used for things that can heavily load the server. Workaround scripts are available. #!/bin/sh # # Automagic update for web statistics # # Run by URL since we can't login under apache - and in any case, we want # certficate-based authentication to work # # /twiki/bin/statistics - Current month for all webs # /twiki/bin/statistics/Main - Just the main web # Can also specify ?logdate=200801;webs=proj1,proj2,... (Would update proj1, proj2 for Jan 2008 # # Since we use https authentication, wget uses administrator certificates... # We also must specify our CA so that wget can validate our server # # wget can succeed even if the update fails, so we check for the expected # completion text. cd `dirname $0` CFG="../lib/LocalSite.cfg" # # Get useful stuff from configuration # DefaultUrlHost='http://localhost:80' ScriptUrlPath='/twiki/binx' grep -P '^\$TWiki::cfg{(DefaultUrlHost|ScriptUrlPath|SmimeCertificateFile|SmimeKeyFile)}' $CFG | sed -e's|\$TWiki::cfg{\(.*\)} = \(.*\)\;|\1=\2|' >$p.tmp . $p.tmp rm $p.tmp # WHOST="$DefaultUrlHost$ScriptUrlPath" # CCSWS= if [ -n "$SmimeCertificateFile" ] && [ -n "$SmimeKeyFile" ]; then CCSWS="--certificate=$SmimeCertificateFile --private-key=$SmimeKeyFile" fi # # Would be nice to get this from LocalSite.cfg... HCSWS= HCSWS='--ca-directory=/etc/pki/tls/ca/' P="`basename $0`" WQ='-q' Q= T='cat' WA= while [ -n "$1" ]; do case "$1" in -d) # debug WQ= T="tee $P.log" ;; -l) # logfile date to process shift if [ -z "$Q" ]; then Q="?logdate=$1" ; else Q="$Q;logdate=$1" ; fi ;; -w) # webs to process shift if [ -z "$Q" ]; then Q="?webs=$1" ; else Q="$Q;webs=$1" ; fi ;; -c) # Client certificate shift CCSWS="$CCSWS --certificate=$1" ;; -k) # Client private key shift CCSWS="$CCSWS --private-key=$1" ;; -X) # Suppress X509 client certificate use CCSWS= ;; -a) # CA certificate bundle for host verification shift HCSWS="$HCASWS --ca-certificate=$1" ;; -A) # CA certificate directory for host verification shift HCSWS="$HCASWS --ca-directory=$1" ;; -x) # Suppress host verification HCSWS='--no-check-certificate' ;; -W) # wget advanced usage switches shift WA="$WA $1" ;; *) cat <<EOF Usage: $P [-d] [-w web[,web...]] [-l logdate] [-X] [-x] [-c cert] [-k key] [-a cafile] [-A cadir] [-W wgetswitch] Updates wiki statistics by touching the statistics update url. The hostname and script url are extracted from LocalSite.cfg. -w - comma-separated list of webs to update. Default is all. -l - logifile dates to update, Format is yyyymm https considerations: o wget will authenticate the host certificate using the default openssl CA. To specify a private CA (or a restricted list), specify your CA directory with -A.or your bundle with -a o To disable host certificate authentication - not a good idea - use -x o Your client certificate and key are specified with -c and -k. They default to the S/MIME signing certificates in LocalSite.cfg (if you have them). o Client authentication is enabled if -c and -k are specified or defaulted. You can disable it with -X, o Some environments may need to specify more advanced wget switches. -W lets you do that. -d enables debugging and will write $P.log. EOF exit 1; ;; esac shift done # After all that, the actual work is quite simple: /usr/bin/wget $WQ $CCSWS $HCSWS $WA $WHOST/statistics$Q -O - | $T | grep $WQ 'End creating usage statistics' # ZZ="$?" # if [ $ZZ != 0 ]; then echo "wiki update $P failed with status $ZZ on `date -R`" else if [ -z "$WQ" ]; then echo "wiki update $P succeeded on `date -R`" ; fi fi if [ "$T" != 'cat' ]; then echo "Check $P.log for details" ; fi-- TimotheLitt - 16 Dec 2008 Thanks Timothe for sharing the runstatistics script. The statistics script can be run as a shell script. Your script comes in handy if that is not possible and if auth is required. This is a rare enough case, I do not think the runstatistics should be part of the TWiki distribution since it is a rare case and since it is not Perl (e.g. platform dependent.) Probably best to create a new how-to page in the Codev web. -- PeterThoeny - 16 Dec 2008 The statistics script can not be run (easily) as a shell script when an installation is secure. For example, files are owned by apache, but logins aren't permitted under apache. selinux is fussy about ownerships, permissions & labelling. While in theory one might create a special group, another account, and deal with the race conditions, it's hardly straightforward. The distribution provides geturl.pl to provide updates in that case. But it requires TWikiGuest to have write access to the web statistics pages - hardly a secure environment. And it does not work at all when authentication is required. Authentication is crucial to the enterprise. It should not -- and I predict will not - be a rare case. TWiki wants to be an enterprise platform - marginalizing secure environments does not seem to be a sound strategy. Shell scripts of this sort are about as portable as perl. This one would not have been any more portable as a perl script as the engine is wget - a system or backtick call from perl would be just about as platform-bound. Re-engineering wget in perl is theoretically possible - but I do leave that as an exercise to the reader! I don't understand the notion that this is a Codev web issue - a solution is basic system management, and belongs where someone who is trying to setup a TWiki will find it. There could be other solutions - but this was easy to implement, and works for me. But it's your project - disposition it however you like. -- TimotheLitt - 17 Dec 2008