Run Scheduled Tasks & Cron Jobs with DeepSeek Harness (DSH)
Automate recurring audits, daily summaries, and repository checks by combining system cron or Task Scheduler with DSH headless mode.
On this page
For reliable, unattended recurring runs with clean logs, use cron / systemd timer + dsh --profile headless. Keep experimental in-app background loops for interactive desktop sessions.
Compare scheduling approaches
Match your scheduling method to the host where DSH runs:
| Method | Best for | Strengths | Watch-outs |
|---|---|---|---|
| Linux/macOS cron + Headless CLI | Servers, NAS, Docker hosts, daily repo digests | Fresh process per run, predictable memory & log files | Export explicit PATH and DSH_HOME in script |
| Windows Task Scheduler + CLI | Always-on Windows workstations | Native OS trigger without keeping a browser open | Verify workspace permissions and shell PATH |
| Experimental background tasks | Active Desktop or Web UI sessions | Quick setup directly inside chat | Stops if the app closes; varies by preview build |
Verify a standalone Headless script first
Always test your command manually before adding it to cron. Save a wrapper script such as run-dsh-job.sh with explicit PATH and DSH_HOME paths:
#!/usr/bin/env bash
set -euo pipefailexport PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
export DSH_HOME="/home/youruser/.dsh"
export DEEPSEEK_API_KEY="sk-your-key"
cd /path/to/your-workspace
dsh --profile headless "Inspect git status and commits from the last 24h, then write a concise summary to reports/daily.md"
>> /var/log/dsh-cron.log 2>&1
In production, load keys from a chmod 600 env file (source ) or rely on saved credentials inside /.dsh.envDSH_HOME/.credentials.yaml.
Wire it into cron with overlap protection
Once bash run-dsh-job.sh succeeds manually, schedule it in three steps:
- 01
Make the script executable
Run
chmod +x /path/to/run-dsh-job.shso cron does not fail withPermission denied. - 02
Add a crontab entry
Run
crontab -eand add a schedule, e.g. daily at 9:00 AM:0 9 * * * /path/to/run-dsh-job.sh. - 03
Prevent overlapping runs
Wrap the command with
flock -n /tmp/dsh-job.lockso a slow run never collides with the next trigger.
Set three guardrails for unattended runs
Because nobody is clicking approval dialogs during a cron run, define strict boundaries up front:
Use a dedicated workspace
Point scheduled jobs to an isolated folder or separate Git branch rather than your primary checkout.
Bound token spend
Scope prompts to specific files and output lengths, and set monthly spending limits in your API provider console.
Capture full logs
Redirect both stdout and stderr to a log file so failed runs are immediately diagnosable.
Never instruct scheduled runs to force-push, delete databases, or overwrite unbacked directories. Have the agent write a draft report or branch for human review instead.
Scheduled tasks FAQ
Why does cron say dsh: command not found when manual runs work?
Cron runs with a minimal PATH and skips shell profiles like /.bashrc or nvm. Check which dsh and export the full Node 24 bin directory inside your script.
Can I schedule DSH jobs inside Docker?
Yes. Trigger docker compose run --rm dsh dsh --profile headless ... from your host crontab while reusing the persistent dsh_home volume. See the Docker guide.
Will headless cron runs interfere with my Web UI?
headless and web are separate profiles. Keep their target workspaces separate so a background job does not edit the same file you have open interactively.
Profile isolation and headless invocation follow the DSH CLI behavior reference, checked .