NickTheGreek 160 Report post Posted December 29, 2017 Hi, I wrote this script in order to add a line to root crontab if it does not already contain such line. The script also checks if the crontab is empty. Is there a better way to achieve this? Code: cronList=$(sudo crontab -u root -l) if [ $(echo $cronList | grep -c "@weekly /home/user/command") -eq 0 ]; then if [ -z "$cronList" ]; then echo "@weekly /home/user/command" | sudo crontab -u root - else (sudo crontab -u root -l; echo "@weekly /home/user/command" ) | sudo crontab -u root - fi fi Thank you https://ubuntuforums.org/showthread.php?t=2315654 Quote Share this post Link to post Share on other sites