cross is now running Foswiki 2.1.3 Beta 1. Please open a task for any issues.
TIP FortunePlugin is not installed on

Fortune Plugin

This plugin uses the Unix/Linux fortune command to insert a random fortune into a topic. On windows environments, or if fortune is not installed, it uses the CPAN Fortune implementation.


The following macros are implemented:
  • %FORTUNE{"database" LENGTH="S"}% Insert a random fortune into the topic from the named "database".
    • LENGTH parameter (optional) can be set to S or SHORT to select short fortunes, and L or LONG for long fortunes. This option only works if the unix fortune-mod program is used.
  • %FORTUNE_LIST{"database"}% List the contents of the named database
  • %FORTUNE_DB_LIST{}% List the available database files in the fortune directory.


Example: %FORTUNE{"foswiki" LENGTH="S"}%

If installed, a random fortune from the foswiki database will appear here:
%FORTUNE{"foswiki" LENGTH="S"}%

Example: %FORTUNE_LIST{"foswiki"}%

If installed, the list of fortunes in the foswiki database

Example: %FORTUNE_DB_LIST{}%

If installed, the list of fortune databases is shown. Note that two different format results are possible. The Unix fortune-mod program reports the percentage of fortunes supplied by each file. The Perl Fortune module shows a simple fortune count.

Plugin Preferences

There are no perferences that can be set for this plugin. All configuration parameters are set in LocalSite.cfg using the bin/configure interface.

Installation and Configuration

  • Install FortunePlugin using the bin/configure interface or the FortunePlugin_installer from the shell.
  • If fortune_mod is installed on a *nix system
    • Using bin/configure in the Extensions FortunePlugin tab, set {Plugins}{FortunePlugin}{FortuneProgram} to point to the fortune program. Typically /usr/bin/fortune.
    • If you want to use the System provided fortune files, set the {Plugins}{FortunePlugin}{FortuneDBPath} to point to the directory containing the fortune files. Typically this is in /usr/share/fortune. If you don't set this, then Fortune will use fortune files attached to FortunePlugin topic.
  • On a windows system, or if fortune_mod is not installed:
    • Install the Fortune module using CPAN
    • leave {Plugins}{FortunePlugin}{FortuneProgram} unset.
    • leave {Plugins}{FortunePlugin}{FortuneDBPath} unset. The plugin will use fortune files attached to this topic. Or if other fortune files are available, point to the directory containing the fortune files. Typically this is in /usr/share/fortune/. Trailing slash must be included.
  • To enable debug, add the following set to SitePreferences:

How to add a fortune to every page

The =%FORTUNE% macro can be added to the bottom of each page by copying System.WebBottomBarExample to System.WebBottomBar and then adding the following before the copyright tag:
<div style="padding:10px 0; text-align:center;"> %FORTUNE{"foswiki"}% </div>

Creating new fortune files

Fortune files must be created by using the strfile command that is installed on Linux with the fortune-mod package. On Windows environments this can be installed using cygwin. This is beyond the scope of this document.

Create the fortune text file

Using your favorite editor, build a simple text file consisting of each fortune, followed by a single line containing a percent-sign ( % ). Omit the final % after the last fortune. For example, file foswiki contains:

Today there are a variety of wikis, one of them being the wiki you are presently looking at.
Foswiki can be extended with hundreds of plugins

Build the fortune database

"Compile" the file into a .dat file using strfile

> ~ $ strfile foswiki
"foswiki.dat" created
There were 2 strings
Longest string: 93 bytes
Shortest string: 49 bytes

The original foswiki file and the related foswiki.dat file can be placed in the fortune database directory. Or attach it to this topic or to another topic identified in the Foswiki configuration.

For easiest system maintenance and upgrades, it is not recommended to modify or attach files to this topic!

Plugin Info

Change History:  
1.1 (8 Apr 2015) Errors in Config.sp file cause issues on Foswiki 1.2.0
1.0 (31 Dec 2013) Initial release

Topic attachments
I Attachment Action Size Date Who Comment
FortunePlugin.md5md5 FortunePlugin.md5 manage 162 bytes 08 Apr 2015 - 14:05 GeorgeClark  
FortunePlugin.sha1sha1 FortunePlugin.sha1 manage 186 bytes 08 Apr 2015 - 14:06 GeorgeClark  
FortunePlugin.tgztgz FortunePlugin.tgz manage 8 K 08 Apr 2015 - 14:05 GeorgeClark  
FortunePlugin.zipzip manage 11 K 08 Apr 2015 - 14:05 GeorgeClark  
FortunePlugin_installerEXT FortunePlugin_installer manage 4 K 08 Apr 2015 - 14:05 GeorgeClark  
foswikiEXT foswiki manage 1 K 08 Apr 2015 - 14:05 GeorgeClark  
foswiki.datdat foswiki.dat manage 96 bytes 08 Apr 2015 - 14:05 GeorgeClark  
Topic revision: r2 - 08 Apr 2015, GeorgeClark - This page was cached on 23 Jan 2017 - 22:09.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License