Last active
October 18, 2021 22:05
-
-
Save Generator/6467828 to your computer and use it in GitHub Desktop.
DD-WRT syslog HTML generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## DD-WRT Log HTML generator | |
## Instructions: | |
## put script in /tmp/www/ | |
## chmod 700 /tmp/www/log_gen.sh | |
## Add cron job in Administrations panel | |
## */15 * * * * root /tmp/www/log_gen.sh | |
## Page available in http://<routerip>/user/syslog.html | |
## Change nline for number of generated lines | |
# Options | |
nlines="500" | |
in="/var/log/messages" | |
out="/tmp/www/syslog.html" | |
# Leave me alone | |
name=$(nvram get router_name); | |
date=$(date) | |
tail -n $nlines $in | awk -v NAME="$name" -v DATE="$date" 'BEGIN { | |
print "<html><title>"NAME" - Syslog</title>" | |
print "<head><style type=\"text/css\"> \ | |
body, td { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \ | |
color: #5f5f5f; background-color: #ffffff;} \ | |
td.hd { font-weight: bold; background-color: #f5f5f5;} \ | |
</style></head>" | |
print "<center><b>System Log</b><br>(Generated: "DATE")<br><br><table border=1 cellspacing=\"0\" cellpadding=\"1\">" | |
print "<tr><td class=\"hd\">Date/Time</td><td class=\"hd\">Severity</td><td class=\"hd\">Messages</td></tr>" | |
} | |
{ | |
if ( $5 ~ /.crit/ || $5 ~ /.alert/ || $5 ~ /.err/ ) COLOR="red"; | |
else COLOR="#5f5f5f"; | |
print "<tr>" | |
print "<td>"$1" "$2" "$3"</td>" | |
print "<td style=\"color:"COLOR";\">"$5"</td>" | |
print "<td>" | |
} | |
{ | |
for (i=6; i<NF; i++) printf $i " "; | |
print $NF; | |
} | |
END { | |
print "</td></tr>" | |
print "</table></center>" | |
print "</html>" | |
}' > $out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment