Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We run a test script from a cron regularly , before initiating any actions this test script clears the /var/log/messages and after performing the actions it analyzes the data in /var/log/messages . This is not desired behavior as clearing of device logs is involved at start of test.

How can I capture device logs only between when test runs. So that test can analyze only that data?

share|improve this question
up vote 4 down vote accepted

Maybe there are less kludgy ways, but you could run

tail -0f /var/log/messages > captured_logs

while your test script runs; or use

logger -i "Test started"
# ...test script...
logger -i "Test stopped"

(see logger) and grep for the section afterwards from the complete log. Beware, I'm not sure what happens when the logs turn over, so a more robust solution might be to read from syslogds socket (-p option), e.g. with socat

socat UNIX-CLIENT:/var/run/log STDOUT

where something more sophisticated than STDOUT might suit your needs better. (You could even run your own syslogd instance for the specific time, configured (-a option) to capture the logs from this socket.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.