Log Internally to SD card

Discussion in 'Tomato Firmware' started by landa, Feb 28, 2009.

  1. landa

    landa LI Guru Member

    How to make tomato to send the logs to sd instead of var/log/messages?
  2. landa

    landa LI Guru Member

    Is not possible?
  3. bogderpirat

    bogderpirat Network Guru Member

    you could try putting something like

    echo "\n\n\n" >> /pathto/sdcard/dir/messages 
    cat /var/log/messages >> /pathto/sdcard/dir/messages
    ln -fs /pathto/sdcard/dir/messages /var/log/messages
    in your init script.

    it will copy the contents that the firmware has gathered in the messages-file to your external sd card after inserting three new lines (denoting a new round of logs) and then create a symbolic link named /var/log/messages that points to the messages-file on your sdcard, overwriting the logfile that we beforehand copied over.

    note that if you don't want a continuous log (i.e. the log from the current uptime is enough for you, you don't need logs that span several reboots of the router), you can just omit line 1 and change switch the >> for a single > in line 2.

    also note that by the time that script runs, the sd card must already be mounted. if it doesn't work for you, it's most likely because the script runs before that. you can then just delay the execution by adding a "sleep 5" or something similar - you'll have to tinker with the timing yourself.
  4. landa

    landa LI Guru Member

    Thank you for the script.

    I want the logs to be saved only in memory card (/mmc/log/messages) and not be saved in RAM. Also I dont want to lose logos after restart.

    sleep 5
    echo "\n\n\n" >> /mmc/log/messages 
    cat /var/log/messages >> /mmc/log/messages
    ln -fs /mmc/log/messages /var/log/messages
    Please, tell me if the code is ok.

    PS: echo "\n\n\n" - what this do? >> - what this do?

    Thank you!!!
  5. bogderpirat

    bogderpirat Network Guru Member

    yes, that should do.

    your logfile might become quite large, as this script will cause any current log to be appended to the previous logs. echo "\n\n\n" will put three new lines before every new log, it's merely an aesthetic thing. ">>" in bash will append its preceding parameter to the latter parameter, in this case, we're appending three new lines to the logfile and then append the current logfile that is in ram to the sd-card's logfile. ln then creates a link in place of the usual messages-file that directs to the file on your sd card.
  6. landa

    landa LI Guru Member

    The script in not working. Messages are saved in both folders. I want the logs to be saved only in memory card (/mmc/log/messages) and not be saved in RAM.
    There is another way?
  7. bogderpirat

    bogderpirat Network Guru Member

    it's not being saved in ram. the only thing that is saved in ram is a reference to the file on the sd card.
  8. landa

    landa LI Guru Member

    Thank you. Now I noticed that in the /var/log/ is just a shortcut to the file on card.

    You are the master!!! :thumbup:
  9. landa

    landa LI Guru Member

    Instead of "\n\n\n" can I put something else? Can I write a text?
    Ex: "new log"
  10. bogderpirat

    bogderpirat Network Guru Member

    sure, why not.
  11. mstombs

    mstombs Network Guru Member

    Not sure this is going to work as the busybox syslog is setup to use two fixed size log files which rotate (to prevent occupying too much ram). Might be better to kill the syslogd and restart with preferred config?

    BusyBox v1.12.2 (2008-11-16 03:35:24 PST) multi-call binary
    Usage: syslogd [OPTION]...
    System logging utility.
    Note that this version of syslogd ignores /etc/syslog.conf.
            -n              Run in foreground
            -O FILE         Log to given file (default=/var/log/messages)
            -l n            Set local log level
            -S              Smaller logging output
            -s SIZE         Max size (KB) before rotate (default=200KB, 0=off)
            -b NUM          Number of rotated logs to keep (default=1, max=99, 0=purge)
            -R HOST[:PORT]  Log to IP or hostname on PORT (default PORT=514/UDP)
            -L              Log locally and via network (default is network only if -R)
  12. xppx99

    xppx99 Addicted to LI Member

    Logging to a external device with the script provided by bogderpirat will result on saving the router's flash memory? Or from this point of view, it is useless?

  13. landa

    landa LI Guru Member

    The script will save only the logs on SD card. The script can be edited to save the logs on the USB stick.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice