I am using the following trap:
trap OnExit EXIT
And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, when etc..
Is any of this possible?
I am using the following trap:
trap OnExit EXIT
And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, when etc..
Is any of this possible?
1. who - as another user cannot send signals to your processes, it is most likely that it will be the process owner user (the root user still can, but I don't know a way to find out if root kills your process).
2. why - maybe something like this:
echo "Why did you interrupted the process?" && read why && echo $why > log
(I'm not sure what you mean under why).
3. how - as BASH receives the same signal if the user presses Ctrl + C or if he sends an interrupt via kill, AFAIK it is impossible to find out how exactly did the interrupt happen.
4. when - that's easy, use the date command:
date > log
EDIT: if you meant determining the signal type under "why" and "how", then see this Q&A on StackOverflow.