Setting up a local model is the easy half. The moment the work has to happen with nobody watching the screen, a nightly digest, a folder of PDFs to summarise, an inbox to triage, the model stops being a chat window and becomes a job. A job needs three things: a way to call the model without a terminal, a scheduler to call it, and an answer to what happens when the machine was asleep at three in the morning.
Key takeaways
- Every runtime here can be called with no person present:
ollama run <model> "<prompt>", Ollama’s HTTP API on port 11434, orllama-cliandllama-serverfrom llama.cpp. - Each platform ships its own scheduler: cron and systemd timers on Linux, launchd on macOS, Task Scheduler on Windows. All four run the same command line.
- The five-minute model keep-alive is the trap that catches people. A job that fires after the model has been unloaded pays a cold load every single time.
- Missed runs are normal rather than broken. systemd timers and launchd both catch up on the next wake, cron does not.
- Give the job somewhere to write. Output that goes nowhere is output you cannot debug.
Calling a model without a terminal
The Ollama CLI takes a prompt as an argument, which is all a scheduler needs. The reference shows a model run with a prompt and an image path in the same string, and, in its embeddings section, an example where the text arrives on standard input instead and the output is a JSON array of numbers rather than prose (Ollama CLI reference):
ollama run gemma4 "What's in this image? /Users/jmorgan/Desktop/smile.png"
echo "Hello world" | ollama run nomic-embed-text
The surrounding commands are the same ones you use by hand: ollama pull fetches a model, ollama ls lists what is on disk, ollama ps shows what is currently in memory, ollama stop unloads, and ollama serve runs the HTTP server (Ollama CLI reference). The last of those is a separate command from ollama run, so the model should be pulled and the server started ahead of time rather than left to the job. A scheduled command runs the job and nothing else.
The HTTP API is the more controllable route. The endpoint runs on port 11434, and the request takes a model, a prompt and a stream flag that turns the token-by-token response off for a single result (Ollama API reference):
curl http://localhost:11434/api/generate -d '{
"model": "gemma4",
"prompt": "Summarise this in one sentence:",
"stream": false
}'
Two more fields earn their place in scheduled work. format takes either the string json or a JSON schema, which is what turns a free-text answer into something a script can parse (Ollama structured outputs). options carries the per-request sampling settings, and the reference’s own example sets temperature, top_p and a seed there (Ollama API reference).
llama.cpp does the same job from the other end of the stack. llama-cli takes the prompt with -p, reads it from a file with -f, and -st runs a single turn and exits, which is the flag that makes it usable from a script rather than a keyboard (llama-cli documentation). The server side exposes POST /completion for the native shape and POST /v1/chat/completions for the OpenAI-compatible one, and it listens on 127.0.0.1 by default, on port 9931 (llama-server documentation). If that server is reachable by anything other than the machine it runs on, the same documentation offers --api-key, which accepts several keys as a comma-separated list.
Four schedulers for the same job
| Platform | Scheduler | Where the schedule lives | What it does while the machine sleeps |
|---|---|---|---|
| Linux | cron | five fields in a crontab | Skips the run |
| Linux | systemd timer | OnCalendar= in a timer unit | Catches up on resume |
| macOS | launchd | StartCalendarInterval in a plist | Runs at the next wake |
| Windows | Task Scheduler | schtasks /Create /SC ... | Not covered by the schtasks reference |
cron takes five time fields: minute 0-59, hour 0-23, day of month 1-31, month 1-12, and day of week 0-7, where 0 and 7 are both Sunday. There are shortcuts for the common cases, and @daily is defined as 0 0 * * * (crontab(5)). The daemon “examines cron entries every minute” (crontab(5)), so the granularity is a minute and nothing finer.
cron also sets three environment variables itself. SHELL is set to /bin/sh, and LOGNAME and HOME come from the owner’s entry in /etc/passwd (crontab(5)). MAILTO decides where the output of a job goes: set it to an empty string and the mail is suppressed, otherwise the job’s output is mailed to the owner. The manual page’s own example redirects to a file instead, which is the right habit for a job that will run unattended for months:
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
A systemd timer is the better tool on Linux when the machine sleeps. OnCalendar= takes calendar expressions and can appear more than once in a unit, and a timer unit paired with a service of type oneshot runs that service when the timer elapses (systemd.timer(5), systemd.service(5)). Two settings decide how precisely the job fires: AccuracySec= defaults to one minute and lets the manager coalesce wakeups, while RandomizedDelaySec= defaults to zero and exists to stretch events apart so that several timers do not fire at the same instant. Persistent=true stores the last trigger time on disk, so a timer that should have fired while the machine was off runs as soon as it comes back (systemd.timer(5)).
# /etc/systemd/system/ollama-digest.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/digest.sh
# /etc/systemd/system/ollama-digest.timer
[Timer]
OnCalendar=*-*-* 07:00:00
Persistent=true
[Install]
WantedBy=timers.target
The timer only fires once it is active, and it only comes back after a reboot if it is enabled. The [Install] section with WantedBy=timers.target is the documented way to pull a timer in at boot (systemd.special(7)); without it, systemctl enable has nothing to install. With it, systemctl enable --now ollama-digest.timer enables the timer and starts it in one step (systemctl(1)).
launchd is the macOS equivalent and has one behaviour that matters for laptops: where cron skips a job while the computer sleeps, “launchd will start the job the next time the computer wakes up” (launchd.plist(5)). If several intervals pass before the machine wakes, they are merged into one run. StartCalendarInterval takes a dictionary of minute, hour, day, month and weekday values, and its semantics are similar to crontab(5).
Task Scheduler on Windows is driven from the command line through schtasks, whose /Create switch takes the task name, the command to run and the schedule type. The /SC values include MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE and ONEVENT, and /MO refines the type, with DAILY accepting 1 to 365 days (Microsoft schtasks reference).
schtasks /Create /SC DAILY /TN "Ollama digest" /ST 07:00 /TR "cmd /c ollama run gemma4 \"Summarise my notes\" > %USERPROFILE%\digest.txt"
Jobs worth scheduling
The useful scheduled work is narrow: input arrives, a model reads it, a file changes. A daily summary of whatever landed in a feed folder is the simplest version, and the same shape covers reviewing a directory of PDFs, tagging new photos, classifying support tickets, or drafting a changelog from a diff. Each of them needs the same three pieces, and only the first is about AI:
- A command that produces one result and exits.
- A scheduler entry that runs it.
- A file the job writes, so there is a record to read when something looks wrong.
Where the output has to be structured rather than prose, put a schema in the format field and let the job fail loudly on a parse error instead of writing a half-parsed record into a folder.
What breaks at 3am
The model was unloaded. Ollama’s documentation states that “By default models are kept in memory for 5 minutes before being unloaded” (Ollama FAQ). A job that runs every hour therefore pays a cold model load on every single run. Two settings fix it: keep_alive on the request keeps that model resident, and OLLAMA_KEEP_ALIVE changes the default for every model on the server. A request-level keep_alive overrides the server-wide setting (Ollama FAQ). A negative value keeps the model loaded indefinitely, and 0 unloads it immediately after the response. To preload without generating anything, the FAQ’s own command is ollama run llama3.2 "".
The server was not running. If Ollama runs as a systemd service on Linux, the FAQ documents systemctl edit ollama.service for setting environment variables under [Service], followed by systemctl daemon-reload and systemctl restart ollama (Ollama FAQ). A scheduled job does not start it, so unless the service is enabled at boot (the Linux install guide’s sudo systemctl enable ollama, Ollama on Linux), a reboot can leave a job firing into a closed port.
The output disappeared. This is the one that costs an afternoon. cron mails job output to the owner unless MAILTO is empty (crontab(5)), and on a machine with nothing able to deliver that mail the output ends up nowhere. Redirect it to a file in the same line.
The machine was asleep. A laptop that is closed at 07:00 will skip a cron job and will not run it later (launchd.plist(5)). launchd runs it at the next wake. A systemd timer catches up on resume, and Persistent=true covers the case where the machine was powered off entirely.
Two jobs overlapped. The Ollama FAQ notes that if too many requests reach the local server it returns a 503 overloaded error, and that OLLAMA_MAX_QUEUE sets how many requests can be queued before that happens, with a default of 512 (Ollama FAQ). The same FAQ puts the default for OLLAMA_NUM_PARALLEL, the number of requests each model processes at once, at 1 on most backends (MLX on Metal picks a conservative default of its own instead), so overlapping jobs wait in line rather than run side by side. A job that fans out into one request per file over a large folder should send them one at a time or in small batches, or raise the queue limit.
The output was prose when the script wanted data. The format field with a JSON schema is the fix, and the same documentation advises passing the schema in the prompt as well so the model is grounded by it (Ollama structured outputs).
What This Means
This is analysis, not fact: scheduling a local model moves the interesting decision out of the prompt and into the job definition. The prompt asks for a summary; the job definition decides what happens when the summary is wrong. A job that appends to a file can be wrong and cost nothing. A job that sends email, deletes files or spends money cannot be wrong safely, so it needs a human in the loop or a much stronger test harness than a prompt.
Running the work locally still matters for this pattern. A nightly job over your own notes does not hand those notes to a hosted model, and the shape of a scheduled job suits a local one, because nobody is waiting on a response. The trade is that the job inherits the local model’s limits, including the idle behaviour that unloads weights after five minutes, and that cost is worth paying deliberately rather than discovering it in a log.
The Bottom Line
Pick the scheduler your platform already ships, pick the model call you can run by hand first, then schedule it. On Linux, a systemd timer with OnCalendar= and Persistent=true handles the sleeping case better than cron, and cron is still the shortest path when you want one line and no unit files. On macOS, use launchd, and on Windows, schtasks /Create.
Whatever you choose, the model has to be resident when the job fires, the output needs a file, and the command needs to parse. Ollama’s keep_alive and OLLAMA_KEEP_ALIVE handle the first, redirecting stdout handles the second, and the format field with a JSON schema handles the third.
The pieces are all documented: How to Call a Local LLM API from Your App for the request layer, Local AI Out of Memory: How to Fix It for the failures that show up when a job asks for more than the machine can hold, and How to Move Local AI Models to a New Machine for when the job moves to different hardware. The rest of our local AI coverage is under Local AI coverage.