The way with the least dependencies would be to simply utilize crontab
and run-parts
.
First, setup your user crontab to run a script for each schedule (e.g., crontab -e
):
@hourly /path/to/run-hourly
@daily /path/to/run-daily
@weekly /path/to/run-weekly
@monthly /path/to/run-monthly
This would be similar to sym-linking each of those scripts to the respective /etc/cron.{hourly,daily,weekly,monthly}
on Debian, but with the benefit of allowing the owning user to run them instead of root.
Second, define each script to run its jobs. For the simplest case, each script can use run-parts
to run all executable job scripts within its specified directory.
#!/bin/bash
#/path/to/run-hourly
run-parts /path/to/hourly/jobs
#!/bin/bash
#/path/to/run-daily
run-parts /path/to/daily/jobs
#!/bin/bash
#/path/to/run-weekly
run-parts /path/to/weekly/jobs
#!/bin/bash
#/path/to/run-monthly
run-parts /path/to/monthly/jobs
Each script must also have execute permissions set:
chmod +x /path/to/run-{hourly,daily,weekly,monthly}
Third, sym-link any desired job to the respective job directory. E.g.,
chmod +x /path/to/job
ln -s /path/to/job /path/to/daily/jobs/
Alternatively, each schedule script could be defined to search for jobs in a common directory per project. Assuming each project is located under /path/to/projects
and each project has descendant jobs/{hourly,daily,weekly,monthly}
, then /path/to/run-hourly
could be defined as:
#!/bin/bash
#/path/to/run-hourly
JOBS=$(find /path/to/projects -type f -path '*/jobs/hourly/*')
while read -r JOB; do
"$JOB"
done <<< "$JOBS"