Muwatta Malik, Book 20, Hadith 247 (USC-MSA)

Yahya related to me from Malik from Humayd bin Qays from Mujahid Abu'l Hajjaj from Ibn Abi Layla from Kab ibn Ujra that the Messenger of Allah, may Allah bless him and grant him peace, said to him, "Perhaps your pests are troubling you?" He replied that indeed they were, and the Messenger of Allah, may Allah bless him and grant him peace, said, "Shave your head and fast three days or feed six poor men or sacrifice a sheep."

حَدَّثَنِي عَنْ مَالِكٍ، عَنْ حُمَيْدِ بْنِ قَيْسٍ، عَنْ مُجَاهِدٍ أَبِي الْحَجَّاجِ، عَنِ ابْنِ أَبِي لَيْلَى، عَنْ كَعْبِ بْنِ عُجْرَةَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ لَهُ ‏"‏ لَعَلَّكَ آذَاكَ هَوَامُّكَ ‏"‏ ‏.‏ فَقُلْتُ نَعَمْ يَا رَسُولَ اللَّهِ ‏.‏ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ احْلِقْ رَأْسَكَ وَصُمْ ثَلاَثَةَ أَيَّامٍ أَوْ أَطْعِمْ سِتَّةَ مَسَاكِينَ أَوِ انْسُكْ بِشَاةٍ ‏"‏ ‏.‏

sunnah.com

also referenced under: Book 20, Hadith 944 (In-Book)