Improved fix for the newline at the end of crontabs

Fixes issue #15699 and improves PR #15771
Merge pull request #15915 from Jille/improve-15771

Improved fix for the newline at the end of crontabs