A CLI utility for scheduling cron jobs that executes shell scripts.
npm install cli-cron-schedulerBy Diego Felipe (
A powerful and flexible CLI tool to schedule cron jobs, handle retries, log outputs, and send email notifications on failures or specific outputs.
- Schedule Cron Jobs with custom scripts.
- Retry Mechanism for failed jobs.
- Email Notifications on failure or specific output conditions.
- Logging of job outputs to a file.
---
``bash`
npm install -g cron-scheduler
---
1. Create a .env file in your project root based on the provided .env.sample:
`env`
SMTP_HOST=smtp.example.com
SMTP_PORT=465
SMTP_USER=your-email@example.com
SMTP_PASS=your-email-password
2. Ensure that your shell script files have executable permissions:
`bash`
chmod +x your-script.sh
---
`bash`
cron-scheduler schedule ./backup.sh "0 0 *" --log ./backup.log --on-fail-email user@example.com --retry 3 --on-output "success:notify,fail:retry"
- ./backup.sh: Path to your shell script."0 0 *"
- : Cron expression (daily at midnight).--log
- : (Optional) Path to the log file.--on-fail-email
- : (Optional) Email address to notify on failure.--retry
- : (Optional) Number of retry attempts on failure.--on-output
- : (Optional) Define output conditions and actions."success:notify,fail:retry"
- Example:
`bash`
cron-scheduler schedule ./script.sh "/5 *" --log ./script.log
- Runs the script every 5 minutes and logs the output.
`bash`
cron-scheduler schedule ./script.sh "0 1 *" --on-fail-email admin@example.com
- Runs the script daily at 1 AM and sends an email if it fails.
`bash`
cron-scheduler schedule ./script.sh "0 12 1" --retry 2 --on-output "success:notify"
- Runs every Monday at noon, retries twice on failure, and notifies on success.
---
Ensure these are correctly configured in your .env file:
- SMTP_HOST: SMTP server host.SMTP_PORT
- : SMTP server port (e.g., 465 for SSL).SMTP_USER
- : SMTP username (usually your email).SMTP_PASS
- : SMTP password.
---
- Email Not Sending: Check SMTP configurations in your .env file.chmod +x
- Script Not Executing: Ensure the script has executable permissions ().npm install -g cron-scheduler` and ensure your system PATH includes npm global binaries.
- Global CLI Not Recognized: Try re-installing globally with
---
Pull requests are welcome! For major changes, open an issue first to discuss what you would like to change.
---