| Name | Exec Macro |
|---|---|
| Vendor | Andre Lüpke |
| Authors | Andre Lüpke |
| Homepage | http://confluence.atlassian.com/display/CONFEXT/Exec+Macro |
| Issue Management | n/a |
| Categories | Content Macros |
| Version | 0.1 |
| Availability | Confluence v2.1.3 to v2.10-m1 |
| State | Stable |
| Support |
|
| License | Freeware / Open Source (BSD) |
| Price | Free |
| Release Docs | http://confluence.atlassian.com/display/CONFEXT/Exec+Macro |
| Java API Docs | n/a |
| Download Source | http://confluence.atlassian.com/download/attachments/162839/confluence-macro-exec-0.1.src.zip?version=1 |
| Download JAR | confluence-macro-exec-0.1.jar |
Description/Features
Confluence macro to display output of executed commands or include local file content in a page.
The main reason, why I created this macro was, that I wanted to be able to use small scripts, like linux one-liners, to create dynamic content in a conluence page. The Scripting and External Content Macros is already quite powerful, but sometimes I just want to be able to use the power of command line tools
An additional advantage is, that you can use any programming language you like.
The reason for the include file macro was mainly, that I wanted to be able to schedule some procedures to update the content of a file or FTP content updates files to my webserver for publishing.
| Warning Please be careful when using this macro in an production environment, as executing arbitrary commands on the webserver might cause serious security risks. However the macro supports some security checks through the parameters in the properties files. |
Usage
Exec Macro Parameters
- command the command itself must be specified as the first parameter and is unnamed (see examples)
- output - defines how the output should be rendered
- html - the output returned by the command contains html-tags and therefore takes care of all the needed formatings
- wiki - the output returned by the command contains confluence wiki markup
Includefile Macro Parameters
- file the filename itself must be specified as the first parameter and is unnamed (see examples)
- output - defines how the output should be rendered
- html - the output returned by the command contains html-tags and therefore takes care of all the needed formatings
- wiki - the output returned by the command contains confluence wiki markup
Exec Macro Properties
For the exec macro there is a properties file ( exec.properties) where the directory needs to be set in which all executable scripts are located. This is done out of security reasons. The file is located in the root folder of the jar file.
exec_dir=/home/weblogic/confluence_scripts/
Includefile Macro Properties
For the includefile macro there is a properties file ( includefile.properties) where the directory needs to be set which contains all includeable files. This is done out of security reasons. The file is located in the root folder of the jar file.
includefile_dir=/home/weblogic/confluence_include/
Examples
Here are some examples on how this macro can be used in combination with some small Linux scripts. More suggestions are of course very welcome.
Example (exec)
Show free disk space as pie charts.
{exec:diskSpaceChart.sh|output=wiki}
df | grep '/home\|/opt' | awk '{ print "{chart:title=disk usage on " $5
"}\n|| || used || available || \n|| bytes || " $2 /1024 /1024 " || " $3 /1024 /1024 " || \n{chart}" }'

Example (exec)
Show a history of number of commits into a local cvs system.
{exec:cvsCommitsPerDay.sh|output=wiki}
echo '{chart:title=cvs commit timeline|type=line|width=800|legend=true|height=300|ylabel=commits
|dataOrientation=vertical}'
echo '|| Day || number of commits ||'
cvs history -c -a | awk '{ user[CODEGEIST:$2]++; } END { for (i in user) { print "| " i " | " user[i] " | "; } }'
| sort -k 2
echo '{chart}';

Example (exec)
Display the number of commits per users in a bar chart.
{exec:cvsCommitsPerUser.sh|output=wiki}
echo '{chart:title=cvs commits per user|type=bar}'
echo '|| user || number of commits ||'
cvs history -c -a | awk '{ user[CODEGEIST:$5]++; } END { for (i in user) { print "| " i " | " user[i] " | "; } }'
echo '{chart}';

Example (exec)
View the most recent commits into the local cvs and replace the actions remove, add und modify as different icons.
{exec:cvsChanges.sh|output=wiki}
echo '|| action || date || user || file ||'
cvs history -c -a | sort -k 2 | tail -n 20 | sed 's/^A/\(\+\)/' | sed 's/^M/\(!\)/' | sed 's/^R/\(\-\)/'
| awk '{print "| " $1 " | " $2 " " $3 " | " $5 " | " $7 " | " }'

Example (includefile)
Use the includefile macro to include files that contain wiki markup.
{includefile:driveStats.txt|output=wiki}
{chart:title=disk usage on drive c:}
|| || used || available ||
|| bytes || 6.75313 || 3.01384 ||
{chart}

Example (includefile)
Embedding the includefile macro into other macros, like chart.
{chart:title=nested includefile macro}
{includefile:driveStatValues.txt|output=wiki}
{chart}
|| || used || available || || bytes || 6.75313 || 3.01384 ||

Version History
0.1 Initial Release
TODO
- one possible feature would be an additional output parameter value 'noformat'
- possibility to specify different execution- and include-directories per space


Comments (6)
Feb 20, 2006
Bob Swift says:
I think this will be very useful tool! I would like the ability to inline the sc...I think this will be very useful tool! I would like the ability to inline the scripts and control the security issues like the other scripting macros.
Feb 21, 2006
aluepke says:
Bob, glad you like the macro :) I have been thinking about inlining scripts as ...Bob, glad you like the macro
I have been thinking about inlining scripts as well, but with the current limited security features the risk would be too high. However I had a look at your proposed security enhancement and it looks quite promising.
I am currently thinking about donating these macros to your scripting collection. Interested?
Feb 21, 2006
Bob Swift says:
Yes, that would be good and pretty easy to do. I can define a couple of new Jira...Yes, that would be good and pretty easy to do. I can define a couple of new Jira components you would own for each new macro for issue tracking. We would need to coordinate a bit on releases. You would need to commit your macro source, update the plugin definition and then the rest of the project stuff would be taken care of. Let me know what you want to do and when. Everything is built under 1.4.4 to support earlier releases although I am only testing on 2.1.3+ now.
Jan 02, 2007
Peter Tester says:
Even it might increase security risk: what about supporting command line options...Even it might increase security risk: what about supporting command line options for the script to be executed. Any useful script I would like to embed needs at least one input parameter.
Jan 04, 2007
aluepke says:
The security risk might indeed be quite big. That's why I would recommend, that ...The security risk might indeed be quite big. That's why I would recommend, that you create a small ' wrapper' script, which will call the script you like with the parameters you need (see diskSpaceChart.sh). This is the way I use the script currently.
Apr 17
Carl Bourne says:
Hi, Is there a way to pass a command line argument to the external script or s...Hi,
Is there a way to pass a command line argument to the external script or shell?
Regards,
Carl