Need help building Dashboard widget that displays Log file
-
I need a widget that displays the last 5 lines of a text logfile that is made from a bash script. The output of this script to the logfile is quite simple:
Tue Jan 1 04:29:43 MST 2013 4.2.2.2 Ping FAILED
Tue Jan 1 04:29:56 MST 2013 8.8.8.8 Ping FAILED
Tue Jan 1 04:30:09 MST 2013 8.8.4.4 Ping FAILED
Tue Jan 1 04:30:11 MST 2013 ALL PINGS FAILED
Tue Jan 1 04:30:11 MST 2013 REQUESTING REBOOT…
Tue Jan 1 04:30:11 MST 2013 DSL MODEM REBOOTING!I can get this in a shell with tail -5 /var/logfile.log but I'm not sure how to do this in a widget format.
Thank you
-
There are several widgets that display logs, some more complex than others. Have a look at the snort widget (in packages), havp widget (also in packages), and firewall logs widget.
What you're after would be easier than those, they do a bit of parsing before displaying, but you could perhaps use them as a basis for what you're trying to accomplish.
Or at least to see how widgets work in general.
-
Thank you. I looked at the code for those widgets and learned how to make my own. It is quite simple:
$file = "/var/log/DSLModemUptimeMonitor.log"; $contents = file($file); $string = array_slice($contents,-6); $string1 = array_reverse($string); ?> | # havp version echo implode(" ", $string1); ?> | -
Very good, nice and simple :-)
Eventually we'll probably have a general-purpose log widget that lets someone choose any of the files in /var/log to show in a widget. Shouldn't be too hard to do, but it's one of those things that nobody has thought to take the time for yet.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginPrivacy Policy · Cookie Policy