173
Chapter 12: Status Reports
12.5.2 Creating custom widgets for the Dashboard
To run a custom script inside a dashboard widget:
Createalecalled"widget-<name>.sh"inthefolder/etc/config/scripts/ where <name>canbeanything.Youcanhaveas
many custom dashboard files as you want.
Insidethisleyoucanputanycodeyouwish.Whenconguringthedashboard,choose"widget-<name>.sh"inthedropdown
list.Thedashboardwillrunthescriptanddisplaytheoutputofthescriptcommandsdirectlyonthescreen,insidethespecic
widget.
The best way to format the output would be to send HTML commands back to the browser by adding echo commands in the
script:
echo '<table>'
You can of course run any command and its output will be displayed in the widget window directly.
Belowisanexamplescriptwhichwritesthecurrentdatetoale,andthenecho'sHTMLcodebacktothebrowser.TheHTML
codegetsanimagefromaspecicURLanddisplaysitinthewidget.
#!/bin/sh
date >> /tmp/test
echo '<table>'
echo '<tr><td> This is my custom script running </td></tr>'
echo '<tr><td>'
echo '<img src="http://www.vinras.com/images/linux-online-inc.jpg">'
echo '</td></tr>'
echo '</table>'
exit 0