Display Message Question

I'm have a script that I am creating and I want the dmesg command to only show output for the current day and the day before. What would be the command to make this work?

Thanks

What sort of output are you looking for? If it's hardware errors, have a look at /var/opt/resmon/log/event.log

One way to get the output of dmesg by date would be to have a scheduled job that runs dmesg each day and saves the output for a dated file. You can then use the previous ones to eliminate duplicate records, something like:-

thislog=/var/mydmesg/`date +%Y%m%d`

dmesg > $thislog

grep -vf accumulated $thislog > $thislog.temp
mv $thislog.temp $thislog

cat accumulated $thislog > accumulated.temp
mv accumulated.temp accumulated

From this, you should get a file each day if you schedule it daily. I suppose you could schedule it weekly or monthly instead and get a weekely/monthly file if you wish. If you want to get fractions of a day, you just need to add the time into the definition of $thislog

I've not tested this, and it depends what you expect to get.

It might be worth archiving the accumulated file each boot.

I hope that this helps,
Robin
Liverpool/Blackburn
UK

I was wanting just a command or two to get the output. I was going to try to use:

dmesg | grep `date +%b%e`
dmesg | grep `TZ=GMT+24 date +%b%e`

But it doesn't want to work (at least on the first nine days of the month).

The problem there is that the date entry in the log is fixed width without a leading zero for the day-of-the-month.

You may need to do something like this:-

typeset -R2 DOM=`date +%e`
dmesg | grep "`date +%b`$DOM"

DOM=`TZ=GMT+24 date +%e`
dmesg | grep "`TZ=GMT+24 date +%b`$DOM"

Does that help?

Robin

I will try it and see if that works.

---------- Post updated at 08:28 AM ---------- Previous update was at 08:22 AM ----------

That looks like it worked. I will keep testing it out and making sure it works. I appreciate your help!

---------- Post updated at 02:32 PM ---------- Previous update was at 08:28 AM ----------

Is this supposed to be ran as part of a bash script?

Yes. Save the commands to a file, make it executable to yourself with:-

chmod o+x filename

..... and then schedule it however you wish.

It could be a manual task (not really the best), the default scheduler cron or an external / 3rd party scheduler.

Robin

I am getting typeset: not found.

This works in any shell but C-shell and with most time zones:

today=`date "+%b %e"`
yesterday=`TZ=$TZ+24 date "+%b %e"`
dmesg | egrep "^($today|$yesterday) "

What shell are you running in? If you are not sure, you can confirm this with the output of the command ps -f

You error suggests you are not in bash or ksh, so we need to be sure first.

Robin