Run a Make Target with Cron
To run a Makefile target on a schedule, cd into the project directory first, then call make with the target name. make needs to find the Makefile in the working directory, which cron does not set for you.
The crontab line
Run crontab -e and add (2:30 AM daily):
30 2 * * * cd /home/user/project && /usr/bin/make deploy >> /home/user/project/make.log 2>&1
Always cd first
make looks for a Makefile in the current directory. Cron starts in the user's home with no project context, so cd /path && is required or you get 'No targets specified and no makefile found'.
Use the absolute path to make
If you see 'make: command not found', use /usr/bin/make (find it with which make) because cron's PATH is minimal.
Specify the target
make deploy runs the deploy: target. Omit the name to run the first target in the file.
FAQ
How do I run a make target from cron?
30 2 * * * cd /path/project && /usr/bin/make deploy runs the deploy target at 2:30 AM. The cd is required so make finds the Makefile.
Why does cron say 'No makefile found' when make works manually?
Cron doesn't set your project as the working directory. Add cd /path/project && before make so it finds the Makefile.
Why 'make: command not found' in cron?
Cron's PATH is minimal. Use the absolute path /usr/bin/make (find it with 'which make').