The tourists, who were bowled out for 245 by Essex last weekend, collapsed from 101-2 to 192-8 at Grace Road.
But uncapped Shanaka shared an unbroken stand of 122 with Rangana Herath (28 not out) to take Sri Lanka to 318-8.
The first of three Tests against England begins at Headingley on Thursday.
Sri Lanka, who conceded a first-innings deficit of 158 in the draw with Essex, were again troubled by a Leicestershire side showing nine changes from their previous first-class match against Northamptonshire.
With Test captain Angelo Mathews rested, his stand-in Dinesh Chandimal won the toss but they immediately lost Dimuth Karunaratne, who was bowled by Atif Sheikh on the fourth delivery of the match.
Kaushal Silva (38) and Kusal Mendis (65) steadied the ship, but 21-year-old Rob Sayer dismissed them both as the Sri Lanka collapse began.
The middle order showed little resistance, with all six Leicestershire bowlers claiming scalps.
When Jigar Naik had Dushmantha Chameera caught behind just after tea, the tourists looked in danger of being bowled out for less than 200.
However, Shanaka went on the offensive, hitting nine fours and three sixes in his 115-ball stay and will resume on Saturday looking for a fourth first-class hundred.
Sri Lanka were playing for the first time since wicketkeeper Kusal Perera’s ban for missing a drugs test was lifted.
“It’s great news for us that the ban has been lifted, he’s a wonderful cricketer and we’ve missed him,” said coach Graham Ford.
“He is a good player in all formats and I am sure the selectors will think about him for the one-day format.
“I’m not sure what is happening with the officials in terms of him playing in the Test squad but it’s just great news to know that he is available for selection again.” (Courtesy BBC Sport)