Operating System - HP-UX
1821642 Members
2885 Online
109633 Solutions
New Discussion юеВ

sample cron to capture Dmesg

 
SOLVED
Go to solution
D Block 2
Respected Contributor

sample cron to capture Dmesg

can someone please supply a sample cron entry
for capturing output from "dmesg".

thanks in advance.
Tom
Golf is a Good Walk Spoiled, Mark Twain.
9 REPLIES 9
Peter Godron
Honored Contributor

Re: sample cron to capture Dmesg

Tom,
could you please clarify?
dmesg is a cyclic buffer, so do you want to have the output of dmesg redirected into a log file (dmesg >> /tmp/log.log) ?
Regards
Stephen Keane
Honored Contributor

Re: sample cron to capture Dmesg

From man dmesg ...


DESCRIPTION
dmesg looks in a system buffer for recently printed diagnostic messages and prints them on the standard output. The messages are those printed by the system when unusual events occur (such as when system tables overflow or the system crashes). If the - argument is specified, dmesg computes incrementally) the new messages since the last time it was run and places these on the standard output. This is typically used with cron (see cron(1)) to produce the error log /var/adm/messages by running the command:

/usr/sbin/dmesg - >> /var/adm/messages

every 10 minutes.

so something like


10 * * * * /usr/sbin/dmesg - >> /var/adm/messages

Or whatever log file you want to use.
A. Clay Stephenson
Acclaimed Contributor

Re: sample cron to capture Dmesg

There is really a flaw in your logic. It's already been explained to you that dmesg is a circular buffer and therefore of limited capacity. Even if the "-" options is used to only output the delta's there is a non-zero proability of missing data --- even with a very short sampling period. If messages are rapidly hitting the dmesg buffer then even a cron every minute might lose data. Dmesg is really only intended to record data when no other facilities (like syslog) are available such as boot time.
If it ain't broke, I can fix that.
twang
Honored Contributor

Re: sample cron to capture Dmesg

you may find output of dmesg from /var/sam/log/samlog
ypu don't have to capture its output.
D Block 2
Respected Contributor

Re: sample cron to capture Dmesg

I wanted to clarify where my request came from... after a system audit (analysis of both h/w and s/w and SPOFs).. one item reads:

"there is no entry in cron to capture the output of dmesg at a regular interval."


so, maybe what I have to do to resolve this item from the audit is:

run "dmesg" only once a week or once a day.


Golf is a Good Walk Spoiled, Mark Twain.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: sample cron to capture Dmesg

Okay, given that constraint then I would create 2 cron entries:

1) One per day to print the actual dmesg buffer contents (no "-")
2) One every 10 minutes or so to print the delta's


1 0 * * * /usr/sbin/dmesg >> /var/adm/dmesg.log
2,12,22,32,42,52 * * * * /usr/bin/dmesg - >> /var/adm/dmesg.log

You might want to actually write a script that outputs the "date" output followed by dmesg.


If it ain't broke, I can fix that.
D Block 2
Respected Contributor

Re: sample cron to capture Dmesg

ok, thanks for all your inputs here!
Golf is a Good Walk Spoiled, Mark Twain.
Bill Hassell
Honored Contributor

Re: sample cron to capture Dmesg

The security audit:

"there is no entry in cron to capture the output of dmesg at a regular interval."

is not aware that dmesg (for HP-UX) has an easy workaround. The "-" option does two things: it reports only what has been added since the last dmesg - command, and two: it timestamps the new messages, something is missing from other Unix-flavor cron solutions. The man page and the default cron job example in /usr/newconfig/var/spool/cron/crontab.root shows you exactly how to log every dmesg entry into a log file. The 1-liner:

05,15,25,35,45,55 * * * * /usr/sbin/dmesg - >>/var/adm/messages

takes care of the audit requirement. Although a lot of Unix flavors suggest the filename "messages" , I think dmesg.log is a lot more intuitive.


Bill Hassell, sysadmin
D Block 2
Respected Contributor

Re: sample cron to capture Dmesg

The dmesg in cron - bill's suggestion is a good one.
Golf is a Good Walk Spoiled, Mark Twain.