Hi there!
I'm trying to update the crontab from a GNU Make file. The idea is like this: I look through the existing cron table and filter out all entries marked as mine (via the comment) and save that to a temporary file. Then I add my jobs to that temporary file and make it a new cron table. That way the make file can be run several times without harming other people's jobs.
This is the relevant part of the make file:
crontab.tmp: $(CRON_FILES)
@echo -n "Generating new cron table combining existing one with a new one ..."
if $$(crontab -l); then crontab -l | grep -v "MAX-CRON-JOB"; fi > $@
@cat $(CRON_FILES) | awk '{print $$0, " ## MAX-CRON-JOB"}' >> $@
@echo "OK"
.PHONY: cronjobs
cronjobs: crontab.tmp
@echo -n "Installing cron commands... "
@crontab $<
@echo "OK"
The troubling part is this line:
if $$(crontab -l); then crontab -l | grep -v "MAX-CRON-JOB"; fi > $@
When the cron table is empty it somehow breaks the make, while the respective generated bash command:
if $(crontab -l); then crontab -l | grep -v "MAX-CRON-JOB"; fi > crontab.tmp
Works OK from the command line.
Here is an error from the make (nothing particularly informative, if you ask me...):
Generating new cron table combining existing one with a new one ...if $(crontab -l); then crontab -l | grep -v "MAX-CRON-JOB"; fi > crontab.tmp
make: *** [crontab.tmp] Error 1
What am I missing here?