Skip to content

Instantly share code, notes, and snippets.

@Generator
Last active October 18, 2021 22:05

Revisions

  1. Generator revised this gist Sep 7, 2013. 1 changed file with 11 additions and 14 deletions.
    25 changes: 11 additions & 14 deletions log_gen.sh
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,11 @@
    ## DD-WRT Log HTML generator
    ## Instructions:
    ## put script in /tmp/www/
    ## chmod 744 /tmp/www/log_gen.sh
    ## 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"
    @@ -19,36 +20,32 @@ 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 { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    body, td { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #ffffff;} \
    td { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #ffffff;} \
    td.hd { font-weight: bold; font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #f5f5f5;} \
    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 bgcolor=#F5F5F5><td class=\"hd\">Date/Time</td><td class=\"hd\">Severity</td><td class=\"hd\">Messages</td></tr>"
    print "<tr><td class=\"hd\">Date/Time</td><td class=\"hd\">Severity</td><td class=\"hd\">Messages</td></tr>"
    }
    {
    if ( $5 == "user.crit" || $5 == "user.emerg" ) color="red";
    else COLOR="black";
    if ( $5 ~ /.crit/ || $5 ~ /.alert/ || $5 ~ /.err/ ) COLOR="red";
    else COLOR="#5f5f5f";
    print "<tr>"
    print "<td><font color=black>"$1" "$2" "$3"</font></td>"
    print "<td><font color="COLOR">"$5"</font></td>"
    print "<td><font color=black>"
    print "<td>"$1" "$2" "$3"</td>"
    print "<td style=\"color:"COLOR";\">"$5"</td>"
    print "<td>"
    }
    #Print Messages
    {
    for (i=6; i<NF; i++) printf $i " ";
    print $NF;
    }
    END {
    print "</font></td></tr>"
    print "</td></tr>"
    print "</table></center>"
    print "</html>"
    }' > $out
  2. Generator revised this gist Sep 6, 2013. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions log_gen.sh
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,17 @@
    ## */15 * * * * root /tmp/www/log_gen.sh
    ## Page available in http://<routerip>/user/syslog.html

    # Options
    nlines="500"
    in="/var/log/messages"
    out="/tmp/www/syslog.html"

    tail -n 1000 $in | awk 'BEGIN {
    print "<html><title>Syslog</title>"
    # 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 { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #ffffff;} \
    @@ -20,18 +26,18 @@ tail -n 1000 $in | awk 'BEGIN {
    td.hd { font-weight: bold; font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #f5f5f5;} \
    </style></head>"
    print "<center><b>System Log</b><br><br><table border=1 cellspacing=\"0\" cellpadding=\"1\">"
    print "<center><b>System Log</b><br>(Generated: "DATE")<br><br><table border=1 cellspacing=\"0\" cellpadding=\"1\">"
    print "<tr bgcolor=#F5F5F5><td class=\"hd\">Date/Time</td><td class=\"hd\">Severity</td><td class=\"hd\">Messages</td></tr>"
    }
    {
    if ( $5 == "user.crit" || $5 == "user.emerg" ) color="red";
    else color="black";
    else COLOR="black";
    print "<tr>"
    print "<td><font color=black>"$1" "$2" "$3"</font></td>"
    print "<td><font color="color">"$5"</font></td>"
    print "<td><font color="COLOR">"$5"</font></td>"
    print "<td><font color=black>"
    }
  3. Generator revised this gist Sep 6, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions log_gen.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    ## chmod 744 /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

    in="/var/log/messages"
    out="/tmp/www/syslog.html"
  4. Generator created this gist Sep 6, 2013.
    47 changes: 47 additions & 0 deletions log_gen.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/sh
    ## DD-WRT Log HTML generator
    ## Instructions:
    ## put script in /tmp/www/
    ## chmod 744 /tmp/www/log_gen.sh
    ## Add cron job in Administrations panel
    ## */15 * * * * root /tmp/www/log_gen.sh

    in="/var/log/messages"
    out="/tmp/www/syslog.html"

    tail -n 1000 $in | awk 'BEGIN {
    print "<html><title>Syslog</title>"
    print "<head><style type=\"text/css\"> \
    body { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #ffffff;} \
    td { font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #ffffff;} \
    td.hd { font-weight: bold; font-size: 12px; font-family: \"tahoma\", \"sans-serif\", \"arial\", \"helvetica\"; \
    color: #5f5f5f; background-color: #f5f5f5;} \
    </style></head>"
    print "<center><b>System Log</b><br><br><table border=1 cellspacing=\"0\" cellpadding=\"1\">"
    print "<tr bgcolor=#F5F5F5><td class=\"hd\">Date/Time</td><td class=\"hd\">Severity</td><td class=\"hd\">Messages</td></tr>"
    }
    {
    if ( $5 == "user.crit" || $5 == "user.emerg" ) color="red";
    else color="black";
    print "<tr>"
    print "<td><font color=black>"$1" "$2" "$3"</font></td>"
    print "<td><font color="color">"$5"</font></td>"
    print "<td><font color=black>"
    }
    #Print Messages
    {
    for (i=6; i<NF; i++) printf $i " ";
    print $NF;
    }
    END {
    print "</font></td></tr>"
    print "</table></center>"
    print "</html>"
    }' > $out