I have heard that at one time the Blessed One was staying at Nadika, in the Brick Hall. There he addressed the monks, "Monks, mindfulness of death — when developed & pursued — is of great fruit & great benefit. It gains a footing in the Deathless, has the Deathless as its final end. And how is mindfulness of death developed & pursued so that it is of great fruit & great benefit, gains a footing in the Deathless, and has the Deathless as its final end?
"There is the case where a monk, as day departs and night returns, reflects: 'Many are the [possible] causes of my death. A snake might bite me, a scorpion might sting me, a centipede might bite me. That would be how my death would come about. That would be an obstruction for me. Stumbling, I might fall; my food, digested, might trouble me; my bile might be provoked, my phlegm... piercing wind forces [in the body] might be provoked. That would be how my death would come about. That would be an obstruction for me.' Then the monk should investigate: 'Are there any evil, unskillful mental qualities unabandoned by me that would be an obstruction for me were I to die in the night?' If, on reflecting, he realizes that there are evil, unskillful mental qualities unabandoned by him that would be an obstruction for him were he to die in the night, then he should put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness for the abandoning of those very same evil, unskillful qualities. Just as when a person whose turban or head was on fire would put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness to put out the fire on his turban or head, in the same way the monk should put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness for the abandoning of those very same evil, unskillful qualities. But if, on reflecting, he realizes that there are no evil, unskillful mental qualities unabandoned by him that would be an obstruction for him were he to die in the night, then for that very reason he should dwell in joy & rapture, training himself day & night in skillful qualities.
"Further, there is the case where a monk, as night departs and day returns, reflects: 'Many are the [possible] causes of my death. A snake might bite me, a scorpion might sting me, a centipede might bite me. That would be how my death would come about. That would be an obstruction for me. Stumbling, I might fall; my food, digested, might trouble me; my bile might be provoked, my phlegm... piercing wind forces [in the body] might be provoked. That would be how my death would come about. That would be an obstruction for me.' Then the monk should investigate: 'Are there any evil, unskillful mental qualities unabandoned by me that would be an obstruction for me were I to die during the day?' If, on reflecting, he realizes that there are evil, unskillful mental qualities unabandoned by him that would be an obstruction for him were he to die during the day, then he should put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness for the abandoning of those very same evil, unskillful qualities. Just as when a person whose turban or head was on fire would put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness to put out the fire on his turban or head, in the same way the monk should put forth extra desire, effort, diligence, endeavor, undivided mindfulness, & alertness for the abandoning of those very same evil, unskillful qualities. But if, on reflecting, he realizes that there are no evil, unskillful mental qualities unabandoned by him that would be an obstruction for him were he to die during the day, then for that very reason he should dwell in joy & rapture, training himself day & night in skillful qualities.
"This, monks, is how mindfulness of death is developed & pursued so that it is of great fruit & great benefit, gains a footing in the Deathless, and has the Deathless as its final end."
That is what the Blessed One said. Gratified, the monks delighted in the Blessed One's words.
See also: AN 6.19.