AdminByShell

Summary: A collection of ways to assist sysadmin of pmwiki using shell tools
Version:
Prerequisites:
Status:
Maintainer: Peter Bowers
Discussion: AdminByShell-Talk
Users: (View? / Edit)

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer. How can I use linux shell tools to examine, search, and otherwise process PMWiki pages?

Description

Various ways to use linux shell tools to process wiki pages

Notes

Running arbitrary shell commands on pages (security based on root-controlled /usr/local/bin location of scripts):
(:shellout cmd=customcommand args="some arguments":)
see http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/48570
see http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/48603

Finding a list of all categories:
See http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/48030

Converting wiki pages to text files for further processing:
WIKID_DIR=/var/www/html/pmwiki/wiki.d
TEXTDIR=/var/www/html/pmwiki/export
cd "$WIKID_DIR"
for i in "$@"
do
	grep '^text=' "$i" | sed -e 's/^text=//' -e 's/%0a/\n/g' -e 's/%25/%/g' >${TEXTDIR}/${i}.txt
done

Converting wiki pages to text files for external processing:
* Install Cookbook:WikiSh recipe and run the command {(cp page [...] TEXTFILE--dirname)}. "TEXTFILE--" is a special prefix to make it use text files rather than pages in its operations. You must give it appropriate permissions via $Enable... as well as having an existing directory to write to. Note that directories are relative from the pmwiki root rather than the wiki.d directory.

Converting from text files back to wiki pages:
See ImportText -- just copy the text files into the import directory

Converting from text files back to wiki pages without the Import (assuming existing pages):
May work. May not. Feel free to update this if you fix it. You should really use ImportText.
Attach: Text2Wiki.txtΔ (It's a perl script but has to be named with an uploadable extension, thus the .txt)


From Eemeli Aro (PmWikiUsers:2009-July/055387.html):

I use the following sed scripts for pretty-printing PmWiki page:

alias pmf="sed 's/^text=/text=\n/;s/%0a/\n/g;s/%3c/</g;s/%25/%/g'"
alias pmp="sed '
 /^text=/ {h;d}          # copy pattern space -> hold space and clear pattern space
 s/^[^=]\+:.*//          # delete history lines (no '=' before ':')
 $ {                     # '$' addresses last line in input stream
   G                     # append \n + hold space to pattern space
   s/\ntext=/\n/
   s/%0a/\n/g            # these replacements are also done for the last line
   s/%3c/</g             # unless it's a history line (usually it is)
   s/%25/%/g
 }
 /^$/ d                  # delete empty lines
 :A
   s/^[^=]\{1,9\}=/ &/   # insert spaces if 1..9 characters are in front of '='
 tA                      # repeat if replacement took place
                         # now there should be ten characters in front of '='
 s/^\([^=]\+\)=/\1 | /   # replace first '=' by ' | '
'"

pmf Group.PageName will print all of the fields of the page, but with the urlencoded newlines, < and % characters translated to their proper values.

pmp Group.PageName will reformat the printout to ignore diffs and other non-current data, print the header fields first and a bit more clearly formatted, followed by the text with the decoded characters.

Perl version of Eemeli's sed script: Attach:pmp-pl.txtΔ (by Oliver Betz)

SteP 2009-10-02: this version should work also when the page history is null, see ExpireDiff. Tested on Windows with GNU sed 4.1.4.

  /^text=/ h
  s/^[^=]\+:.*//
  $ {
    g
    s/text=/\n/
    s/%0a/\n/g
    s/%3c/</g
    s/%25/%/g
    p
    d
  }
  /^text=/ d
  /^$/ d
  :A
    s/^[^=]\{1,9\}=/ &/
  tA
  s/^\([^=]\+\)=/\1 | /

Slow Categories

I use the following via (:shellout cmd=categories.sh:) for a Categories page:

 
!/bin/sh

wikidir=/srv/www/htdocs/pmwiki

(cd ${wikidir}/wiki.d
ls | grep -v ,del | xargs grep 'targets=.' | cut -d= -f2- | tr ',' '\012'  |
   grep Category | sort -u) |
   sed -e 's/^Category\.\(.*\)/Category.\1\?action=browse|\1/' -e 's/^/[[/'  -e 's/$/]]\\\\/'
 

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

  • PageFileFormat (includes an alternate shell script to access text from command line)
  • PageTopStore - a great way to be able to naturally use full shell capabilities on wiki pages, both read & write, and treat them as simple text

Contributors

Several of the code examples come from Chris Cox thru pmwiki-users posts. See related links to those posts.

Comments

See discussion at AdminByShell-Talk