WikiDevi.Wi-Cat.RU:DD-WRT/View Logfile in Browser without Local Syslogd (log.sh)
- View the last 1000 lines from your router's logfile in your browser without a locally running syslogd (i.e. Kiwi)
First Method: Script Generated Live-content
Initial post in German forum: SOLVED: messages (logdatei) formatiert über browser aufrufen)
#!/bin/sh
echo '<HTML><HEAD><TITLE>Logfile</TITLE></HEAD>'
echo '<BODY>'<br>nvram get router_name
echo ' Logfile:<br><pre>'
/usr/bin/tail -n 1000 /var/log/messages
echo '</BODY></HTML>'
To use this script you first need to enable syslog on your router without stating an IP. Then the log will be saved in /var/log/messages. You can do this under Administration->Services and then scroll down to the "System Log" section. Click "Enable" and leave "Remote Server" empty. After you saved the script under /tmp/www/ as "log.sh" you must mark it as executable with "chmod +x /tmp/www/log.sh". You can do that by saving the following in your startup script:
echo -en "#!/bin/sh\necho '<HTML><HEAD><TITLE>Logfile</TITLE></HEAD>'\necho '<BODY>'\nnvram get router_name\necho ' Logfile:<br><pre>'\n/usr/bin/tail -n 1000 /var/log/messages\necho '</BODY></HTML>'" > /tmp/www/log.sh
To view the log in your browser point it to "http://<routerip>/user/log.sh"
It appears that the above method doesn't work under some versions of v24 as shell scripts need to be created in the cgi-bin folder in order for the webserver to execute them.
If you find the previous startup script doesn't work, try the following:
mkdir /tmp/www/cgi-bin
echo -en "#!/bin/sh\necho '<HTML><HEAD><TITLE>Logfile</TITLE></HEAD>'\necho '<BODY>'\nnvram get router_name\necho ' Logfile:<br><pre>'\n/usr/bin/tail -n 1000 /var/log/messages\necho '</BODY></HTML>'" > /tmp/www/cgi-bin/log.sh
chmod +x /tmp/www/cgi-bin/log.sh
and use http://<routerip>/user/cgi-bin/log.sh
to access it.
Second Method: Static Generated HTML
Note that it is reported that script-generated content will not be delivered by the web server in v24-RC4 and v24-RC5, maybe other versions are affected too (see User-HTML (skript generiert) funzt nicht :( in the German forum). If you just get an empty page if using the first method you may use this workaround:
echo -en "#!/bin/sh\nrm /tmp/www/syslog.html\necho '<HTML><HEAD><TITLE>Logfile (Generated: ' >> /tmp/www/syslog.html\ndate >> /tmp/www/syslog.html\necho ')</TITLE></HEAD><BODY>' >> /tmp/www/syslog.html\nnvram get router_name >> /tmp/www/syslog.html\necho ' Logfile:<br><pre>' >> /tmp/www/syslog.html\n/usr/bin/tail -n 1000 /var/log/messages >> /tmp/www/syslog.html\necho '</pre></BODY></HTML>' >> /tmp/www/syslog.html" > /tmp/www/log_gen.sh
chmod +x /tmp/www/log_gen.sh
Save the above code to your startup script and create a cron job for it. To generate a HTML log every 15 minutes you could use this job:
*/15 * * * * root /tmp/www/log_gen.sh
Your router's syslog is now available on http://<routerip>/user/syslog.html
and will be updated every 15 minutes (or whatever you've set in the cron job).