LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-24-2007, 06:04 AM   #1
Eamo
LQ Newbie
 
Registered: Jun 2007
Posts: 6

Rep: Reputation: 0
Embedded Linux - Preserve log file thats cleared on boot


Hi

Im looking for some advice on how to solve a simple enough issue I have with a portable device that uses a stripped down version of linux with the BusyBox tools.

The problem is that the device clears its log on each boot. I need to preserve the log for auditing. I've tried several different methods but none really give me a elegant solution.

I've tried the following

1. Setup a cron job to copy the log file to a folder which is not cleared on boot with a timestamp in the filename. This achives the aim however it leaves me with a lot of files that are mainly duplicates of each other. Im sure there must be a better way.

2. Using a bash script to do a diff against the live log file and the backup and then append the differences to the bottom of the backup log file. This kinda words but due to the output of the diff command it makes the log file very difficult to read.

One solution that has been mentioned to me is to use syslog to write a copy of the logfile to another directory that is cleared on reboot. I like the sound of this solution as its clean and simple. I've had a look at what seems to be the config file for syslog its at /etc/sysconfig/syslog

It only contains one line which I dont understand at all (yes, I have been googling syslog configuration but havnt managed to get any information to help me understand the line) its:

SYSLOG="-m 0 -b 2 -s 64"

Anyone got any experience with getting syslog to do what I want

Many thanks

Eamo
 
Old 09-24-2007, 06:13 AM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Why not just mount /var/log on whatever non-volatile volume you have? Or symlink it, if that would be easier in your setup. That way all the logs will be preserved transparently to the system.

Beyond that option, it sounds like it is just an issue of getting the correct Bash script to backup the log file. So for example, if the multiple logs are bothering you, why not simply have the script delete any that are more than x hours/days/weeks old?
 
Old 09-24-2007, 07:40 AM   #3
Eamo
LQ Newbie
 
Registered: Jun 2007
Posts: 6

Original Poster
Rep: Reputation: 0
I like your suggestion of adding to the bash script some code that deletes files if they are older than X hours lets say.

I've been searching the net for some information on how to write this script but havnt come up with much.

Even a list of commands that possibly could help would be a good start. Im not afraid of man pages I just dont even know what commands are most suited to getting this result

Regards

Eamo
 
Old 09-24-2007, 08:10 AM   #4
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Here is a very simple script (actually, you can really do the whole thing with just the one line) to remove files from a given directory that are older than a given number of hours. Adjusting the two variables to match your system should work. The third variable allows you to either delete everything, or delete only files matching a specific pattern (I.E. "logfile-*")

Once you have things sent the way you want, you could put the "find ..." line in your boot scripts with the minutes, directory, and file pattern hard-coded in.

Code:
#!/bin/sh
# Very simple script to handle old log files.

# Lifetime of log files
HOURS="2"

# Directory to clean
TARGET="/tmp"

# Filename to match
NAME="*"

find $TARGET -name "$NAME" -mmin +$(($HOURS * 60)) -type f -maxdepth 1 -delete
# EOF
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting linux to boot on embedded system BleedingEdge Linux From Scratch 3 06-19-2005 06:36 AM
Does Linux write what happens at boot to a file ? I can't find anything in var/log . lostboy Linux - General 8 05-07-2003 02:58 PM
Accidentally cleared the password file ForumKid Linux - General 8 03-04-2003 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration