Auto Update Downloaded Ollama Models

I like to keep all models updated, but Ollama does not automatically update downloaded models. This is how I automate updates using a cronjob and Bash script.
~/.local/bin/update-models.sh
#!/usr/bin/env bash
# Update all local models.
models=$(ollama ls | tail -n +2 | awk '{print $1}')
for model in $models
do
echo "Pulling ${model}"
ollama pull $model
done
Run it after 12 AM daily. I introduced delay execution in this blog post.
0 0 * * * sleep $((RANDOM % 3600)); ~/.local/bin/update-models.sh > /dev/null 2>&1

