|
Cookbook /
AdminByShellSummary: A collection of ways to assist sysadmin of pmwiki using shell tools
Version:
Prerequisites:
Status:
Maintainer: Peter Bowers
Discussion: AdminByShell-Talk
Categories: SystemTools Searching
Questions answered by this recipeHow can I use linux shell tools to examine, search, and otherwise process PMWiki pages? DescriptionVarious ways to use linux shell tools to process wiki pages NotesRunning arbitrary shell commands on pages (security based on root-controlled /usr/local/bin location of scripts): Finding a list of all categories:
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: Converting from text files back to wiki pages: Converting from text files back to wiki pages without the Import (assuming existing pages): 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 ' | '
'"
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 CategoriesI 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
See Also
ContributorsSeveral of the code examples come from Chris Cox thru pmwiki-users posts. See related links to those posts. CommentsSee discussion at AdminByShell-Talk |