crontab-installer
crontab-installer copied to clipboard
A simple script to install or remove custom crontab entries
crontab-installer
A simple script to install or remove a custom crontab.
Here's how it works:
-
Create a file
./crontab.txtwith the custom crontab of your project -
Run
./crontab.shto add the crontab entry if it does not already exist -
Run
./crontab.sh --removeto remove the crontab entry
The script detects if the crontab already exists, by looking for a specific format:
# BLANK LINE HERE
# $PWD
YOUR CRONTAB
# BLANK LINE HERE
$PWD is the absolute path of the directory of the crontab.sh script.
The blank lines at the start and end, and the line with the path
should uniquely identify the entry in the complete crontab of the user.
This makes it possible to avoid adding an entry twice,
and to remove the entry.
The script creates this format for you, you don't need to write it manually.
You just create your crontab entry in crontab.txt,
and the script will install it in the above format.
To use this script in a project:
-
Copy
crontab.shto your project, add to version control -
Create
crontab.txtas appropriate for the project, but don't add to version control -
Optionally add
crontab.txt.sampleto version control, without sensitive or deployment-specific information. -
Mark
crontab.txtandcrontab.bakignored in version control, as the crontab entries typically contain sensitive information or settings specific to deployment.
When installing your project in production,
copy crontab.txt.sample to crontab.txt and modify as needed.
Install the crontab by running ./crontab.sh,
uninstall by running ./crontab.sh --remove.