You cannot catch the crash, but you can detect upon the next boot, that the previous run crashed, count it then.
To detect such an event you can write a script that looks at the previous log for the crash specific error messages.
Probably use grep to search /var/lastlog, or /var/dmseg for crash messages.
You can search for panic
You might have to change another script to copy any logs before the get wiped, or to insert a tag to help your search.
Put the script somewhere in the boot scripts (/etc/rc.d/rc.local)
The script can increment a count (how, I cannot think of a way right now).
Probably will have to create your own log (/var/log/crash_count ??)
to keep state.
You may have to move the normal logs (rename, etc.) each time after you check, so as to not recheck the same data twice.
This is just preliminary thinking on this, you will have to work out the details. I have not tried this before, and there may be some subtle problems.
|