Rename pause/resume to disable/enable to align with systemd terminology
-P/-R flags become -D/-E, -E (edit) becomes -e. Functions renamed to disable_job_by_id/enable_job_by_id. Output messages, docs, tests, and demo tapes updated accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e636ea323c
commit
8319924139
6 changed files with 65 additions and 65 deletions
10
CLAUDE.md
10
CLAUDE.md
|
|
@ -20,14 +20,14 @@ The script has two modes controlled by CLI flags:
|
|||
|
||||
- **Job creation** (`-t <time> [-c <cmd> | -f <script> | stdin]`): Generates a systemd `.service` + `.timer` pair with a 6-char hex short ID, reloads the daemon, and enables/starts the timer. Time specs are parsed via `parse_time` which handles natural language (`every 5 minutes`), `date -d` relative/absolute times, and raw systemd OnCalendar values. One-time jobs get `Persistent=false` and `RemainAfterElapse=no` (auto-unload after firing). All jobs log stdout/stderr to the journal via `SyslogIdentifier`. Notifications (`-i` desktop, `-m` email, `-o` include output) use `ExecStopPost` so they fire on both success and failure with status-aware icons/messages. The `-o [N]` flag fetches the last N lines of journal output (default 10) and includes them in the notification body (also configurable in edit mode as `o` or `o=N`). Notification flags are persisted in the service file as a `# SYSTAB_FLAGS=` comment.
|
||||
|
||||
- **Management** (`-P`, `-R`, `-E`, `-L`, `-S`, `-C`, `-h` — mutually exclusive):
|
||||
- `-P <id>` / `-R <id>`: Pause (stop+disable) or resume (enable+start) a job's timer.
|
||||
- `-E`: Opens `$EDITOR` with a pipe-separated crontab (`ID[:FLAGS] | SCHEDULE | COMMAND`). Notification flags are appended to the ID with `:` (`i` = desktop, `e=addr` = email, `o` = output 10 lines, `o=N` = output N lines, comma-separated). On save, diffs against the original to apply creates (ID=`new`), deletes (removed lines), updates (changed schedule/command/flags), and pause/resume (comment/uncomment lines).
|
||||
- **Management** (`-D`, `-E`, `-e`, `-L`, `-S`, `-C`, `-h` — mutually exclusive):
|
||||
- `-D <id>` / `-E <id>`: Disable (stop+disable) or enable (enable+start) a job's timer.
|
||||
- `-e`: Opens `$EDITOR` with a pipe-separated crontab (`ID[:FLAGS] | SCHEDULE | COMMAND`). Notification flags are appended to the ID with `:` (`i` = desktop, `e=addr` = email, `o` = output 10 lines, `o=N` = output N lines, comma-separated). On save, diffs against the original to apply creates (ID=`new`), deletes (removed lines), updates (changed schedule/command/flags), and disable/enable (comment/uncomment lines).
|
||||
- `-L [id] [filter]`: Query `journalctl` logs for managed jobs (both unit messages and command output). Optional job ID to filter to a single job.
|
||||
- `-S [id]`: Show timer status via `systemctl`, including short IDs and disabled state. Optional job ID to show a single job.
|
||||
- `-C`: Interactively clean up elapsed one-time timers (removes unit files from disk).
|
||||
|
||||
Key functions: `parse_time` (time spec → OnCalendar), `_write_unit_files` (shared service+timer creation), `create_job`/`create_job_from_edit` (thin wrappers), `edit_jobs` (crontab-style edit with diff-and-apply), `get_managed_units` (find tagged units by type), `clean_jobs` (remove elapsed one-time timers), `pause_job`/`resume_job` (disable/enable timers), `write_notify_lines` (append `ExecStopPost` notification lines), `build_flags_string`/`parse_flags` (convert between CLI options and flags format).
|
||||
Key functions: `parse_time` (time spec → OnCalendar), `_write_unit_files` (shared service+timer creation), `create_job`/`create_job_from_edit` (thin wrappers), `edit_jobs` (crontab-style edit with diff-and-apply), `get_managed_units` (find tagged units by type), `clean_jobs` (remove elapsed one-time timers), `disable_job_by_id`/`enable_job_by_id` (disable/enable timers), `write_notify_lines` (append `ExecStopPost` notification lines), `build_flags_string`/`parse_flags` (convert between CLI options and flags format).
|
||||
|
||||
## Testing
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ Key functions: `parse_time` (time spec → OnCalendar), `_write_unit_files` (sha
|
|||
./test.sh
|
||||
```
|
||||
|
||||
Runs 44 tests against real systemd user timers covering job creation, status, logs, pause/resume, notifications, time format parsing, error cases, and cleanup. All test jobs are cleaned up automatically via trap.
|
||||
Runs 44 tests against real systemd user timers covering job creation, status, logs, disable/enable, notifications, time format parsing, error cases, and cleanup. All test jobs are cleaned up automatically via trap.
|
||||
|
||||
## Notes
|
||||
|
||||
|
|
|
|||
24
README.md
24
README.md
|
|
@ -82,7 +82,7 @@ systab -t "every day at 6am" -c "df -h" -i -o
|
|||
|
||||
```bash
|
||||
# Edit all jobs in your $EDITOR (crontab-style)
|
||||
systab -E
|
||||
systab -e
|
||||
|
||||
# Show status of all jobs
|
||||
systab -S
|
||||
|
|
@ -99,11 +99,11 @@ systab -L a1b2c3
|
|||
# View logs (filtered)
|
||||
systab -L error
|
||||
|
||||
# Pause a job
|
||||
systab -P <id>
|
||||
# Disable a job
|
||||
systab -D <id>
|
||||
|
||||
# Resume a paused job
|
||||
systab -R <id>
|
||||
# Enable a disabled job
|
||||
systab -E <id>
|
||||
|
||||
# Clean up completed one-time jobs
|
||||
systab -C
|
||||
|
|
@ -111,24 +111,24 @@ systab -C
|
|||
|
||||
### Edit mode
|
||||
|
||||
`systab -E` opens your editor with a pipe-delimited job list:
|
||||
`systab -e` opens your editor with a pipe-delimited job list:
|
||||
|
||||
```
|
||||
a1b2c3 | daily | /home/user/backup.sh
|
||||
d4e5f6:i | *:0/15 | curl -s https://example.com
|
||||
g7h8i9:e=user@host | weekly | ~/backup.sh
|
||||
# aabbcc | hourly | echo "this job is paused"
|
||||
# aabbcc | hourly | echo "this job is disabled"
|
||||
```
|
||||
|
||||
- Edit the schedule or command to update a job
|
||||
- Delete a line to remove a job
|
||||
- Add a line with `new` as the ID to create a job: `new | every 5 minutes | echo hello`
|
||||
- Comment out a line (`#`) to pause, uncomment to resume
|
||||
- Comment out a line (`#`) to disable, uncomment to enable
|
||||
- Append notification flags after the ID with `:` — `i` for desktop, `e=addr` for email, `o` for output (default 10 lines), `o=N` for custom count, comma-separated (e.g., `a1b2c3:i,o,e=user@host`)
|
||||
|
||||
### Job IDs
|
||||
|
||||
Each job gets a 6-character hex ID (e.g., `a1b2c3`) displayed on creation and in status output. Use this ID with `-P`, `-R`, and `-L`.
|
||||
Each job gets a 6-character hex ID (e.g., `a1b2c3`) displayed on creation and in status output. Use this ID with `-D`, `-E`, and `-L`.
|
||||
|
||||
## How it works
|
||||
|
||||
|
|
@ -148,9 +148,9 @@ Job Creation:
|
|||
-o [lines] Include job output in notifications (default: 10 lines)
|
||||
|
||||
Management:
|
||||
-P <id> Pause (disable) a job
|
||||
-R <id> Resume (enable) a paused job
|
||||
-E Edit jobs in crontab-like format
|
||||
-D <id> Disable a job
|
||||
-E <id> Enable a disabled job
|
||||
-e Edit jobs in crontab-like format
|
||||
-L [id] [filter] List job logs (optionally for a specific job and/or filtered)
|
||||
-S [id] Show status of all managed jobs (or a specific job)
|
||||
-C Clean up completed one-time jobs
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ Enter
|
|||
Sleep 500ms
|
||||
Show
|
||||
Sleep 1s
|
||||
Type "EDITOR=nano systab -E"
|
||||
Type "EDITOR=nano systab -e"
|
||||
Sleep 500ms
|
||||
Enter
|
||||
Sleep 3s
|
||||
|
|
@ -83,7 +83,7 @@ Enter
|
|||
Sleep 500ms
|
||||
Show
|
||||
Sleep 1s
|
||||
Type "EDITOR=nano systab -E"
|
||||
Type "EDITOR=nano systab -e"
|
||||
Sleep 500ms
|
||||
Enter
|
||||
Sleep 3s
|
||||
|
|
|
|||
|
|
@ -69,21 +69,21 @@ Sleep 3s
|
|||
Type "q"
|
||||
Sleep 1s
|
||||
|
||||
# Pause a job (uses the first job ID from status)
|
||||
# Disable a job (uses the first job ID from status)
|
||||
Hide
|
||||
Type "./demo/note.sh 'Pausing a job'"
|
||||
Type "./demo/note.sh 'Disabling a job'"
|
||||
Enter
|
||||
Sleep 500ms
|
||||
Show
|
||||
Sleep 1s
|
||||
Type "systab -P $(systab -S 2>/dev/null | grep -m1 'Job:' | awk '{print $2}')"
|
||||
Type "systab -D $(systab -S 2>/dev/null | grep -m1 'Job:' | awk '{print $2}')"
|
||||
Sleep 500ms
|
||||
Enter
|
||||
Sleep 2s
|
||||
|
||||
# Show it's paused
|
||||
# Show it's disabled
|
||||
Hide
|
||||
Type "./demo/note.sh 'Verifying job is paused'"
|
||||
Type "./demo/note.sh 'Verifying job is disabled'"
|
||||
Enter
|
||||
Sleep 500ms
|
||||
Show
|
||||
|
|
@ -98,14 +98,14 @@ Sleep 3s
|
|||
Type "q"
|
||||
Sleep 1s
|
||||
|
||||
# Resume it
|
||||
# Enable it
|
||||
Hide
|
||||
Type "./demo/note.sh 'Resuming the paused job'"
|
||||
Type "./demo/note.sh 'Enabling the disabled job'"
|
||||
Enter
|
||||
Sleep 500ms
|
||||
Show
|
||||
Sleep 1s
|
||||
Type "systab -R $(systab -S 2>/dev/null | grep -m1 'Disabled' -B4 | grep 'Job:' | awk '{print $2}')"
|
||||
Type "systab -E $(systab -S 2>/dev/null | grep -m1 'Disabled' -B4 | grep 'Job:' | awk '{print $2}')"
|
||||
Sleep 500ms
|
||||
Enter
|
||||
Sleep 2s
|
||||
|
|
|
|||
58
systab
58
systab
|
|
@ -18,8 +18,8 @@ opt_edit=false
|
|||
opt_list=false
|
||||
opt_clean=false
|
||||
opt_status=false
|
||||
opt_pause=""
|
||||
opt_resume=""
|
||||
opt_disable=""
|
||||
opt_enable=""
|
||||
opt_filter=""
|
||||
opt_output=""
|
||||
opt_jobid=""
|
||||
|
|
@ -39,9 +39,9 @@ Job Creation Options:
|
|||
-o [lines] Include job output in notifications (default: 10 lines)
|
||||
|
||||
Management Options:
|
||||
-P <id> Pause (disable) a job
|
||||
-R <id> Resume (enable) a paused job
|
||||
-E Edit jobs in crontab-like format
|
||||
-D <id> Disable a job
|
||||
-E <id> Enable a disabled job
|
||||
-e Edit jobs in crontab-like format
|
||||
-L [id] [filter] List job logs (optionally for a specific job and/or filtered)
|
||||
-S [id] Show status of all managed jobs (or a specific job)
|
||||
-C Clean up completed one-time jobs
|
||||
|
|
@ -69,11 +69,11 @@ EXAMPLES:
|
|||
echo "ls -la" | $SCRIPT_NAME -t "next monday at 9am"
|
||||
|
||||
# Edit existing jobs (supports adding notifications via ID:flags syntax)
|
||||
$SCRIPT_NAME -E
|
||||
$SCRIPT_NAME -e
|
||||
|
||||
# Pause and resume a job
|
||||
$SCRIPT_NAME -P <id>
|
||||
$SCRIPT_NAME -R <id>
|
||||
# Disable and enable a job
|
||||
$SCRIPT_NAME -D <id>
|
||||
$SCRIPT_NAME -E <id>
|
||||
|
||||
# View logs for backup jobs
|
||||
$SCRIPT_NAME -L backup
|
||||
|
|
@ -218,26 +218,26 @@ validate_job_id() {
|
|||
grep -q "^$MARKER" "$timer_file" 2>/dev/null || error "Not a managed job: $id"
|
||||
}
|
||||
|
||||
# Pause a job by short ID
|
||||
pause_job() {
|
||||
# Disable a job by short ID
|
||||
disable_job_by_id() {
|
||||
validate_job_id "$1"
|
||||
if ! is_job_enabled "$_job_name"; then
|
||||
echo "Already paused: $1"
|
||||
echo "Already disabled: $1"
|
||||
return
|
||||
fi
|
||||
disable_job "$_job_name"
|
||||
echo "Paused: $1"
|
||||
echo "Disabled: $1"
|
||||
}
|
||||
|
||||
# Resume a job by short ID
|
||||
resume_job() {
|
||||
# Enable a job by short ID
|
||||
enable_job_by_id() {
|
||||
validate_job_id "$1"
|
||||
if is_job_enabled "$_job_name"; then
|
||||
echo "Already running: $1"
|
||||
echo "Already enabled: $1"
|
||||
return
|
||||
fi
|
||||
enable_job "$_job_name"
|
||||
echo "Resumed: $1"
|
||||
echo "Enabled: $1"
|
||||
}
|
||||
|
||||
# Get all managed unit files of a given type (service or timer)
|
||||
|
|
@ -929,7 +929,7 @@ clean_jobs() {
|
|||
|
||||
# Parse command-line options
|
||||
parse_options() {
|
||||
while getopts "t:c:f:im:oP:R:ELSCh" opt; do
|
||||
while getopts "t:c:f:im:oD:E:eLSCh" opt; do
|
||||
case $opt in
|
||||
t) opt_time="$OPTARG" ;;
|
||||
c) opt_command="$OPTARG" ;;
|
||||
|
|
@ -948,9 +948,9 @@ parse_options() {
|
|||
else
|
||||
opt_output=10
|
||||
fi ;;
|
||||
P) opt_pause="$OPTARG" ;;
|
||||
R) opt_resume="$OPTARG" ;;
|
||||
E) opt_edit=true ;;
|
||||
D) opt_disable="$OPTARG" ;;
|
||||
E) opt_enable="$OPTARG" ;;
|
||||
e) opt_edit=true ;;
|
||||
L) opt_list=true ;;
|
||||
S) opt_status=true ;;
|
||||
C) opt_clean=true ;;
|
||||
|
|
@ -982,19 +982,19 @@ parse_options() {
|
|||
|
||||
# Validate mutually exclusive options
|
||||
local manage_count=0
|
||||
[[ -n "$opt_pause" ]] && manage_count=$((manage_count + 1))
|
||||
[[ -n "$opt_resume" ]] && manage_count=$((manage_count + 1))
|
||||
[[ -n "$opt_disable" ]] && manage_count=$((manage_count + 1))
|
||||
[[ -n "$opt_enable" ]] && manage_count=$((manage_count + 1))
|
||||
$opt_edit && manage_count=$((manage_count + 1))
|
||||
$opt_list && manage_count=$((manage_count + 1))
|
||||
$opt_status && manage_count=$((manage_count + 1))
|
||||
$opt_clean && manage_count=$((manage_count + 1))
|
||||
|
||||
if [[ $manage_count -gt 1 ]]; then
|
||||
error "Options -P, -R, -E, -L, -S, and -C are mutually exclusive"
|
||||
error "Options -D, -E, -e, -L, -S, and -C are mutually exclusive"
|
||||
fi
|
||||
|
||||
if [[ $manage_count -gt 0 && -n "$opt_time$opt_command$opt_file" ]]; then
|
||||
error "Management options -P, -R, -E, -L, -S, and -C cannot be used with job creation options"
|
||||
error "Management options -D, -E, -e, -L, -S, and -C cannot be used with job creation options"
|
||||
fi
|
||||
|
||||
if [[ -n "$opt_command" && -n "$opt_file" ]]; then
|
||||
|
|
@ -1012,10 +1012,10 @@ main() {
|
|||
parse_options "$@"
|
||||
|
||||
# Determine mode based on options
|
||||
if [[ -n "$opt_pause" ]]; then
|
||||
pause_job "$opt_pause"
|
||||
elif [[ -n "$opt_resume" ]]; then
|
||||
resume_job "$opt_resume"
|
||||
if [[ -n "$opt_disable" ]]; then
|
||||
disable_job_by_id "$opt_disable"
|
||||
elif [[ -n "$opt_enable" ]]; then
|
||||
enable_job_by_id "$opt_enable"
|
||||
elif $opt_edit; then
|
||||
edit_jobs
|
||||
elif $opt_list; then
|
||||
|
|
|
|||
18
test.sh
18
test.sh
|
|
@ -166,21 +166,21 @@ assert_output "view logs all" "Logs for" $SYSTAB -L
|
|||
assert_output "view logs single job" "$id_recurring" $SYSTAB -L "$id_recurring"
|
||||
|
||||
# ============================================================
|
||||
# Pause / Resume
|
||||
# Disable / Enable
|
||||
# ============================================================
|
||||
|
||||
echo ""
|
||||
echo "${BOLD}--- Pause / Resume ---${RESET}"
|
||||
echo "${BOLD}--- Disable / Enable ---${RESET}"
|
||||
|
||||
assert_output "pause job" "Paused:" $SYSTAB -P "$id_recurring"
|
||||
assert_output "disable job" "Disabled:" $SYSTAB -D "$id_recurring"
|
||||
|
||||
assert_output "show paused state" "Disabled" $SYSTAB -S "$id_recurring"
|
||||
assert_output "show disabled state" "Disabled" $SYSTAB -S "$id_recurring"
|
||||
|
||||
assert_output "pause already paused" "Already paused:" $SYSTAB -P "$id_recurring"
|
||||
assert_output "disable already disabled" "Already disabled:" $SYSTAB -D "$id_recurring"
|
||||
|
||||
assert_output "resume job" "Resumed:" $SYSTAB -R "$id_recurring"
|
||||
assert_output "enable job" "Enabled:" $SYSTAB -E "$id_recurring"
|
||||
|
||||
assert_output "resume already running" "Already running:" $SYSTAB -R "$id_recurring"
|
||||
assert_output "enable already enabled" "Already enabled:" $SYSTAB -E "$id_recurring"
|
||||
|
||||
# ============================================================
|
||||
# Notifications
|
||||
|
|
@ -280,8 +280,8 @@ echo "${BOLD}--- Error cases ---${RESET}"
|
|||
|
||||
assert_failure "missing -t" $SYSTAB -c "echo hello"
|
||||
assert_failure "-c and -f together" $SYSTAB -t "daily" -c "echo hello" -f /nonexistent
|
||||
assert_failure "invalid job ID for -P" $SYSTAB -P "zzzzzz"
|
||||
assert_failure "invalid job ID for -R" $SYSTAB -R "zzzzzz"
|
||||
assert_failure "invalid job ID for -D" $SYSTAB -D "zzzzzz"
|
||||
assert_failure "invalid job ID for -E" $SYSTAB -E "zzzzzz"
|
||||
|
||||
# -o without -i or -m: should succeed (flag accepted, just no notification lines)
|
||||
assert_output "-o without -i/-m creates job" "Job created:" $SYSTAB -t "every 10 minutes" -c "echo bare_output" -o
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue