I am looking for a programmatic way to append to crontab only if the entry does not exist. Also, the exit code must be 0
for both cases where the entry does not exist, or the entry exists.
I tried:
(crontab -l -u root 2>/dev/null | grep -F -v "@reboot /usr/bin/mycommand" || true; echo "@reboot /usr/bin/mycommand 2>&1") | sudo crontab -u root -
(crontab -l -u root 2>/dev/null | grep -F -v "@reboot /usr/bin/mycommand_2" || true; echo "@reboot /usr/bin/mycommand_2 2>&1") | sudo crontab -u root -
But the second still overrides everything in crontab.