Posted on
Artificial Intelligence

Local LLM Automation

Author
  • User
    linuxbash
    Posts by this author
    Posts by this author

Local LLM Automation on Linux: Turn Bash Into Your Private AI Power Tool

If you could pipe your system logs, diffs, and docs into an AI assistant without sending a byte to the cloud, what would you automate first? Local LLMs (Large Language Models) let you do exactly that—right from Bash—so you can summarize logs, draft commit messages, explain commands, and more, all privately and offline.

This post explains why local LLM automation is valuable, how to install it on Linux, and gives you 3 practical Bash automations you can drop into your workflow today.

Why local LLM automation is worth it

  • Privacy by default: Your prompts and data never leave your machine.

  • Always available: Works without internet; ideal for servers and secure environments.

  • Scriptable: Treat the model like any other CLI or service. Pipe in, pipe out.

  • Cost control: Run quantized models on commodity hardware (8–16 GB RAM is often enough).

Modern runtimes like Ollama and llama.cpp make local models easy to install and script, exposing a simple CLI and/or REST API suitable for Bash automation.

What you’ll need

  • A Linux machine with AVX2-capable CPU (most 2015+ x86_64 CPUs) and 8–32 GB RAM.

  • Disk space for models (a few GB per model).

  • Basic CLI tools: curl, jq, git, and build tools if you compile from source.

Install prerequisites

Install common tools you’ll use in the examples.

  • On apt (Debian/Ubuntu):
sudo apt update
sudo apt install -y curl jq git build-essential cmake pkg-config libopenblas-dev
  • On dnf (Fedora/RHEL/CentOS Stream):
sudo dnf install -y curl jq git make gcc gcc-c++ cmake pkgconfig openblas-devel
  • On zypper (openSUSE):
sudo zypper refresh
sudo zypper install -y curl jq git make gcc gcc-c++ cmake pkg-config libopenblas-devel

Choose and install a local LLM runtime

You have two great options. Pick one (you can use both).

Option A: Ollama (the easiest)

Ollama provides a simple CLI and a local REST API, plus one-command model installs.

  • Install (same on most distros; Ollama does not use apt/dnf/zypper packages):
curl -fsSL https://ollama.com/install.sh | sh
  • Ensure the service is running (usually started by the installer):
sudo systemctl enable --now ollama
  • Pull a model and test:
ollama pull llama3
ollama run llama3 "Say hello from a local LLM."

Tip: Other solid models to try: mistral, llama3.2, phi3, neural-chat.

Option B: llama.cpp (bare metal, ultra-lean)

llama.cpp is a fast, minimal runtime you compile yourself. Great for tight systems or custom builds.

  • Build from source:
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
make -j

For CUDA GPU acceleration (optional, requires NVIDIA toolkit):

make -j LLAMA_CUBLAS=1
  • Download a GGUF model (example: Llama 3 8B Q4_0 via a provider; place it under ~/models):
mkdir -p ~/models
# Put your downloaded .gguf file here, e.g.:
# mv ~/Downloads/llama-3-8b-instruct.Q4_0.gguf ~/models/
  • Run a prompt:
./main -m ~/models/llama-3-8b-instruct.Q4_0.gguf -p "Say hello from llama.cpp."

Note: Model availability and licensing vary; always follow the model’s license.

Wire it into Bash

Add a tiny helper to your shell for quick prompts.

  • For Ollama (add to ~/.bashrc or ~/.bash_profile):
ask() {
  local prompt="$*"
  ollama run llama3 "$prompt"
}
  • For llama.cpp (adjust model path as needed):
ask_local() {
  local prompt="$*"
  ~/path/to/llama.cpp/main -m ~/models/llama-3-8b-instruct.Q4_0.gguf -n 256 -p "$prompt"
}

Reload your shell: source ~/.bashrc

Now try: ask Summarize the purpose of systemd in one paragraph.

3 real-world automations you can add today

1) Summarize noisy logs into a human-friendly brief

Turn the last couple hours of service logs into a concise summary.

  • Ollama (simple CLI version):
logs="$(journalctl -u nginx --since '2 hours ago' --no-pager | tail -n 500)"
prompt=$(printf "Summarize the following nginx logs. Highlight errors, recurring issues, and likely root causes. Provide concise bullet points.\n\n%s" "$logs")
ollama run llama3 "$prompt"
  • Ollama (robust REST API version; avoids shell-escaping issues):
logs="$(journalctl -u nginx --since '2 hours ago' --no-pager | tail -n 500 | jq -Rs .)"
json=$(printf '{"model":"llama3","prompt":"Summarize the following nginx logs. Highlight errors, recurring issues, and likely root causes. Provide concise bullet points.\n\n%s","stream":false}' "$logs")
curl -s http://localhost:11434/api/generate -d "$json" | jq -r '.response'
  • llama.cpp:
logs="$(journalctl -u nginx --since '2 hours ago' --no-pager | tail -n 300)"
~/path/to/llama.cpp/main -m ~/models/llama-3-8b-instruct.Q4_0.gguf -n 256 -p "Summarize these nginx logs:\n\n$logs"

Tip: For very long logs, sample or filter with grep -iE 'error|warn|timeout'.

2) Auto-draft Git commit messages from diffs

Create a Git hook to propose a message, which you can then edit.

  • Create .git/hooks/prepare-commit-msg:
#!/usr/bin/env bash
set -euo pipefail

if [ -n "${SKIP_LLM_COMMIT_MSG:-}" ]; then
  exit 0
fi

diff_content="$(git diff --staged)"
[ -z "$diff_content" ] && exit 0

prompt=$(printf "Write a concise conventional commit message (type:scope) with a short subject and a short body.\nFocus on what changed and why.\n\nDiff:\n%s" "$diff_content")

msg="$(ollama run llama3 "$prompt" 2>/dev/null || true)"
[ -n "$msg" ] && { printf "%s\n\n# Drafted by local LLM\n" "$msg" >> "$1"; }
  • Make it executable:
chmod +x .git/hooks/prepare-commit-msg

If you prefer llama.cpp, swap the ollama run line with your main -m ... -p "$prompt" call.

3) Explain any Linux command using its own man page

Ask the model to read the manual and produce a quick-start with examples.

explain() {
  if [ -z "${1:-}" ]; then
    echo "Usage: explain <command>" >&2
    return 1
  fi
  local cmd="$1"
  local manual
  manual="$(man "$cmd" | col -bx | head -c 20000)"
  local prompt
  prompt=$(printf "Explain how to use '%s' with 3–5 practical examples. Base your explanation ONLY on this manual text. Be concise.\n\n%s" "$cmd" "$manual")
  ollama run llama3 "$prompt"
}

Try: explain rsync

Bonus: Calling the local API from Bash

Ollama exposes a local REST API you can hit with curl. Useful for structured scripts and streaming.

  • One-shot completion:
curl -s http://localhost:11434/api/generate \
  -d '{"model":"llama3","prompt":"List 5 safe ways to restart a systemd service on Linux.","stream":false}' \
  | jq -r '.response'
  • Chat-style (stateful) with messages:
curl -s http://localhost:11434/api/chat \
  -d '{
    "model": "llama3",
    "messages": [
      {"role":"system","content":"You are a terse Linux assistant."},
      {"role":"user","content":"What does /etc/resolv.conf do?"}
    ],
    "stream": false
  }' | jq -r '.message.content'

Tips for better results

  • Pick the right model: Smaller instruct-tuned models (llama3, mistral) are fast and good for automation. If you need long context or more reasoning, use a larger model if your hardware allows.

  • Control length: For llama.cpp, -n 256 limits output tokens. For Ollama, use --options via a Modelfile or API parameters like "num_predict".

  • Keep prompts short and specific: Provide role, task, and constraints. Feed only the necessary context (filtered logs, focused diffs).

  • Cache and reuse: Save summaries or embeddings if you’re doing repeated tasks.

  • Stay offline: Block network if you’re processing sensitive data; local LLMs don’t require external calls.

Uninstall or update (quick notes)

  • Ollama: Re-run the installer to update. To stop: sudo systemctl disable --now ollama.

  • llama.cpp: Pull latest main and make -j again. Remove the directory to uninstall.

Conclusion and next steps

Local LLMs let you automate the boring-but-important text work right in Bash—privately, scriptably, and on your terms. Start with:

1) Install Ollama or build llama.cpp.
2) Add the ask function to your shell.
3) Drop in one automation (logs, commits, or explain).

Then iterate: integrate with cron or systemd timers, standardize your prompts, and expand to other tasks (ticket triage, changelog drafting, code review checklists).

If you found this useful, try wiring one of these scripts into your daily workflow today—and share what you automate next.