.local-bin/docs/setup_crontab/Usage.md

63 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## [setup_crontab](../../scripts/setup_crontab)
Sets up automated cron jobs from a configuration file.
## Description
This script manages cron jobs by reading from `mycronjobs.txt` and merging them into the system crontab. It intelligently avoids duplicate entries and ensures the cron service is running.
## Usage
```bash
./setup_crontab.sh
```
## Configuration File
The script expects a cron job definition file at:
`~/.local/bin/mycronjobs.txt`
Example `mycronjobs.txt`:
```
# Daily backup at 2 AM
0 2 * * * /home/user/.local/bin/backup.sh
# Weekly cleanup on Sundays
0 0 * * 0 /home/user/.local/bin/cleanup.sh
```
## Features
- **Smart Merging**: Only adds new jobs, skips existing duplicates
- **Comments Support**: Lines starting with `#` are ignored
- **Service Management**: Automatically starts cron service on Linux
- **Cross-Platform**: Works on Linux (systemd) and macOS (launchd)
## Platform Behavior
### Linux
- Starts cron via `systemctl` if not running
- Uses standard crontab
### macOS
- Uses launchd (cron runs automatically)
- No additional service management needed
## Example Output
```
✅ Added 2 new cron job(s):
+ 0 2 * * * /home/user/.local/bin/backup.sh
+ 0 0 * * 0 /home/user/.local/bin/cleanup.sh
```
Or if jobs already exist:
```
No new cron jobs to add; all jobs already present.
```
## Notes
- The script uses `set -euo pipefail` for strict error handling
- Existing crontab entries are preserved
- Empty lines are ignored during processing