Mishkat al-Masabih 96
‘Abdallah b. ‘Amr said:
God’s messenger came out with two books in his hands and asked, “Do you know what these two books are?” We replied, “No, messenger of God, unless you tell us.” Of the one in his right hand he said, “This is a book from the Lord of the universe containing the names of those who will go to paradise, as well as the names of their fathers and their tribes. It is completed to the last man, so there will never be any increase or diminution in their numbers.” Of the one in his left hand he then said, “This is a book from the Lord of the universe containing the names of those who will go to hell, as well as the names of their fathers and their tribes. It is completed to the last man, so there will never be any increase or diminution in their numbers.” His Companions asked, “What then, messenger of God, is the good of doing anything if the matter is already decided?” He replied, “Follow a right course and keep as near to it as you can, for the last act of one who is to go to paradise will be an act appropriate for those who go to paradise no matter what he may have done; but the last act of one who is to go to hell will be an act appropriate for those who go to hell no matter what he may have done.” God’s messenger then made a gesture with his hands throwing the books away and said, “Your Lord has decided everything about mankind; a section will be in paradise and a section in the blaze.” 

Tirmidhi transmitted it.
وَعَنْ عَبْدِ اللَّهِ بْنِ عَمْرِو بْنِ الْعَاصِ قَالَ: خَرَجَ عَلَيْنَا رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَفِي يَده كِتَابَانِ فَقَالَ: «أَتَدْرُونَ مَا هَذَانِ الكتابان فَقُلْنَا لَا يَا رَسُولَ اللَّهِ إِلَّا أَنْ تُخْبِرَنَا فَقَالَ لِلَّذِي فِي يَدِهِ الْيُمْنَى هَذَا كِتَابٌ مِنْ رَبِّ الْعَالَمِينَ فِيهِ أَسْمَاءُ أَهْلِ الْجَنَّةِ وَأَسْمَاء آبَائِهِم وقبائلهم ثمَّ أجمل على آخِرهم فَلَا يُزَادُ فِيهِمْ وَلَا يُنْقَصُ مِنْهُمْ أَبَدًا ثُمَّ قَالَ لِلَّذِي فِي شِمَالِهِ هَذَا كِتَابٌ مِنْ رَبِّ الْعَالَمِينَ فِيهِ أَسْمَاءُ أَهْلِ النَّارِ وَأَسْمَاء آبَائِهِم وقبائلهم ثمَّ أجمل على آخِرهم فَلَا يُزَادُ فِيهِمْ وَلَا يُنْقَصُ مِنْهُمْ أَبَدًا فَقَالَ أَصْحَابُهُ فَفِيمَ الْعَمَلُ يَا رَسُولَ اللَّهِ إِنْ كَانَ أَمْرٌ قَدْ فُرِغَ مِنْهُ فَقَالَ سَدِّدُوا وَقَارِبُوا فَإِنَّ صَاحِبَ الْجَنَّةِ يُخْتَمُ لَهُ بِعَمَلِ أَهْلِ الْجَنَّةِ وَإِنْ عَمِلَ أَيَّ عَمَلٍ وَإِنَّ صَاحِبَ النَّارِ يُخْتَمُ لَهُ بِعَمَلِ أَهْلِ النَّارِ وَإِنْ عَمِلَ أَيَّ عَمَلٍ ثُمَّ قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ بِيَدَيْهِ فَنَبَذَهُمَا ثُمَّ قَالَ فَرَغَ رَبُّكُمْ مِنَ الْعِبَادِ فريق فِي الْجنَّة وفريق فِي السعير» . رَوَاهُ التِّرْمِذِيُّ وَقَالَ: هَذَا حَدِيثٌ حَسَنٌ غَرِيبٌ صَحِيح