Take the 2-minute tour ×
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.

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

1 Answer 1

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

 
discard

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.