What's new

System Log to USB disk

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Just a heads up for anyone trying to setup logrotate as per the instructions in posts #16 and #18.

As per this post here: http://www.snbforums.com/threads/entware-logrotate-w-o-user-root.15384/ there are a number of changes that need to be made in order to get this working properly.

Firstly to test your setup you can run
Code:
/opt/sbin/logrotate -d /opt/etc/logrotate.conf
to do a dry test run after following the instructions in the above mentioned posts (#16 and #18), this will more than likely throw an error regarding no password being present in the file etc, this is what the link above addresses.

Briefly here is what I found needed to be done in order to get this working correctly on my router:

  1. Create a root user with the name "root" by adding the relevant entries into the /jffs/configs/passwd.add and /jffs/configs/shadow.add files
  2. Add an su entry into the syslog.log portion of the logrotate.conf file so that it will run as your user (not the root user created in step 1 above), assuming your user name is "admin" it should look something like this:
    Code:
    /opt/var/log/syslog.log {
    su admin root
    size 1024k
    weekly
    rotate 9
    postrotate
    killall -HUP syslogd
    endscript
    }
    where "admin" is the name of your user and "root" is the group to which your user belongs (it should always be "root")
  3. Remove the user name from the cronjob entry, so instead of
    Code:
    0 0 * * * admin /opt/sbin/logrotate -f /opt/etc/logrotate.conf &>/dev/null
    it should rather be
    Code:
    0 0 * * * /opt/sbin/logrotate -f /opt/etc/logrotate.conf &>/dev/null
  4. Remove the -f flag from the cron job as this forces logrotate to rotate the logs everytime it runs, as opposed to only rotating them weekly or however you've setup your config. So the cron job should rather look like this then:
    Code:
    0 0 * * * /opt/sbin/logrotate /opt/etc/logrotate.conf &>/dev/null
  5. With the current config as it is in post #16 it has both size and weekly entries for the syslog.log configuration. With it setup this way logrotate will ignore the weekly instruction and will only rotate the log when it reaches 1024k in size. I've changed this to rather use the maxsize option as opposed to size, in conjunction with the weekly option, which will then rotate the log weekly or when it reaches 1024k, whichever comes first. So my entry for syslog.log then looks like this:
    Code:
    /opt/var/log/syslog.log {
    su admin root
    maxsize 1024k
    weekly
    rotate 9
    postrotate
    killall -HUP syslogd
    endscript
    }
And that should do it, with these changes logrotate seems to be humming along just fine on my RT-AC87U.
 
Last edited:
Hi,

I created a post-mount script in /jffs/scripts with this content:
Code:
[B]#!/bin/sh
/bin/sleep 3s[/B]    # give the disk 3 sec to really be ready
[B]/usr/bin/logger -t START_$(basename $0) "started [$@]"[/B]    # Log the start of the script int syslog.log
[B]SCRLOG=/tmp/$(basename $0).log[/B]    # define the own log file for this script
[B]touch $SCRLOG [/B]  # create my own log file for the messages of this script
[B]echo "START_$(basename $0) started [$@]" >> $SCRLOG[/B]    # log the start message
[B]if [ $1 = "/tmp/mnt/[COLOR="Red"]sdcard[/COLOR]" ][/B]    # check if the USB drive is mounted (need to have you own name)
[B]then
/jffs/scripts/syslog-move.sh >> $SCRLOG[/B]    # Start the script to move Syslog
[B]wait[/B]    # wait for the script to finish
[B]fi
if [ "$?" -ne 0 ][/B]    # If error in the execution of the syslog-move script
[B]then
echo "Error in postmount execution! Script: $0" >> $SCRLOG[/B]    # Log the error
[B]else
echo "Postmount execution OK. Script: $0" >> $SCRLOG[/B]    # Log the success
[B]fi
/usr/bin/logger -t STOP_$(basename $0) "return code $?"[/B]   # Log that the script has finished into syslog.log

Of corse you need the syslog-move.sh script as well in the /jffs/scripts folder:
Code:
[B]#!/bin/sh
SOURCE=/tmp/syslog.log[/B]    # original source of the syslog
[B]SYSLOG=/tmp/mnt/[COLOR="Red"]sdcard/Syslog[/COLOR]/syslog.log[/B]    # destination of the syslog - need to by adjusted
joegreat[B]NOW=$(date +"%Y%m%d-%H%M%S")[/B]    # current date and time
[B]mv $SYSLOG $SYSLOG-$NOW[/B]    # rename the previous log with timesith nanotamp
[B]cp $SOURCE $SYSLOG[/B]    # copy current syslog to the new location
[B]rm $SOURCE[/B]    # delete the syslog
[B]ln -s $SYSLOG $SOURCE[/B]   # create a symbolic link from the orginal syslog to the copied one
[B]if [ "$?" -ne 0 ][/B]    # check for error
[B]then
echo "Error in Syslog move! Script: $0"[/B]    # display the error message
[B]exit $?
else
echo "Syslog move OK. Script: $0"[/B]    # display OK message
[B]exit 0
fi[/B]

And finally do not forget to add the execute flag to the scripts:
Code:
[B]chmod a+x /jffs/scripts/*[/B]

Have fun!

With kind regards
Joe :cool:

PS.: Do not forget to backup the /jffs/ content on a save place! The next firmware update may erase the /jffs/ file system...

@joegreat
What editor are you using in the quoted post?
I'd like to enable this, but with nano all the color codes show up as text. Is there any way to strip these out?

Thanks
 
Script to move syslog to usb drive



Hi,

OK. I did some googel-ing :) and put together the following script (stored into /jffs/scripts/) to move syslog to an usb drive (or in my case to the internal sd-card).
It preservers also the old syslog files by renaming them on boot: This is very, very helpful in case of debugging of problems... ;)



The target directory shows in my case the following files:

The current syslog has the default name and the "old one" is renamed with the boot date and time.

Any updates or suggestions are very welcome!

With kind regards
Joe :cool:

Thanks! I find this is good enough as new files are only created upon reboot, which, hopefully, doesn't occur too often.

Cheers!
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top