Skip to content

Instantly share code, notes, and snippets.

@rabidpug
Last active March 3, 2026 00:11
Show Gist options
  • Select an option

  • Save rabidpug/a023ce2b62c4df806671ad19c105f835 to your computer and use it in GitHub Desktop.

Select an option

Save rabidpug/a023ce2b62c4df806671ad19c105f835 to your computer and use it in GitHub Desktop.
Trigger a search for the first 20 cutoff unmet/missing episodes/movies/albums/books by oldest search time in the ARR suite
#!/bin/bash
__help() {
cat << EOF
Please call this script with \$ARR_API_KEY set, and with the following parameters:
$0 sonarr|radarr|lidarr|readarr https://domain:port cutoff|missing
EOF
exit 1
}
if [[ -z "$ARR_API_KEY" ]] || [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]]; then
__help
fi
case $1 in
radarr)
api=v3
sortPart=movie
commandPart=Movies
;;
lidarr)
api=v1
sortPart=album
commandPart=Album
;;
readarr)
api=v1
sortPart=book
commandPart=Book
;;
sonarr)
api=v3
sortPart=episode
commandPart=Episode
;;
*)
__help
;;
esac
curl -fsSL \
-H "X-Api-Key: $ARR_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d "$(curl -fsSL \
-H "X-Api-Key: $ARR_API_KEY" \
"$2/api/$api/wanted/$3?page=1&pageSize=20&sortDirection=ascending&sortKey=${sortPart}s.lastSearchTime&monitored=true" \
| jq -rc --arg name "${commandPart}Search" --arg key "${sortPart}Ids" '{name: $name, $key: [.records[].id]}' \
)" "$2/api/$api/command"
@rabidpug
Copy link
Author

rabidpug commented Feb 24, 2026

Requires curl and jq.

Example systemd service and timer below.
Create the file /etc/arr-search/sonarr.env with locked-down permissions and the contents:

ARR_API_KEY=yourkey

then create the 2 files below, eg in /etc/systemd/system

# arr-missing@.service
[Unit]
Description=Trigger arr missing search for %i.
Wants=arr-missing@%i.timer

[Service]
Type=oneshot
EnvironmentFile=/etc/arr-search/%i.env
ExecStart=/usr/bin/bash /path/to/arr-search.sh %i https://%i.example.com missing

[Install]
WantedBy=multi-user.target
# arr-missing@.timer
[Unit]
Description=Trigger arr missing search for %i
Wants=arr-missing@%i.service

[Timer]
Unit=arr-missing@%i.service
OnCalendar=hourly
RandomizedDelaySec=10m

[Install]
WantedBy=timers.target

Copy both those files, replacing missing with cutoff both in the names and contents of the files.

Then run systemctl enable --now arr-missing@sonarr.timer arr-cutoff@sonarr.timer

You will now have 20 missing and 20 cutoff unmet episodes searched roughly every hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment