Saturday 13 January 2018

programatically enable and disable individual crontab entries

Running as root and using the user clarkeb as an example
To append:
(crontab -u clarkeb -l 2>&1 | grep -v "no crontab" ;echo "*/5 * * * * perl /home/clarkeb/test1.pl") | crontab -u clarkeb –
(crontab -u clarkeb -l 2>&1 | grep -v "no crontab" ;echo "*/5 * * * * perl /home/clarkeb/test2.pl") | crontab -u clarkeb –
(crontab -u clarkeb -l 2>&1 | grep -v "no crontab" ;echo "*/5 * * * * perl /home/clarkeb/test3.pl") | crontab -u clarkeb –
To check:
crontab -u clarkeb -l
To remove test1.pl only and leave test2.pl and test3.pl n place:
crontab -u clarkeb -l  2>&1 | grep -v "test1.pl" | crontab -u clarkeb –

No comments:

Post a Comment