It is possible to run scripts in netbox, both from the web GUI and also on the command line.
However the usage is not very intuitive. so here’s a (very short) introduction.
Basic knowledge
First of all we need to know where to locate the scripts. That one is relatively easy: Place them into a directory scripts/
in the directory where netbox’s manage.py
is located.
The next step is to know how to execute the script (as it is not called by its name alone). Turns out the name of the script consists of the scripts filename (without .py ending) and a second component:
This second component is the class name to be used/called:
linux # grep class scripts/NetBox_DNS_Exporter.py
scripts/NetBox_DNS_Exporter.py:class ZoneExporter(Script):
Putting those things together we get the following command:
linux # ./manage.py runscript "NetBox_DNS_Exporter.ZoneExporter"
Ok, now the first time the script will be called, however it will complain about a missing parameter. This can be passed in JSON format:
linux # ./manage.py runscript "NetBox_DNS_Exporter.ZoneExporter" --data '{"export_path": "/export"}'
Now we should be good to go 🙂
Possible errors
Make sure the database entries are OK (only script name, no path) – there’s been a bug in netbox 4.3.1 that may cause this behavior.
In case a database dump of table core_managedfile
results in something like this you need to fix that first:
COPY public.core_managedfile (id, data_path, data_synced, created, last_updated, file_root, file_path, data_file_id, data_source_id, auto_sync_enabled) FROM stdin;
3 \N 2025-05-15 17:33:20.00775+02 \N scripts /opt/netbox/netbox/scripts/NetBox_DNS_Exporter.py \N \N f
4 \N 2025-05-15 17:38:03.198915+02 \N scripts /opt/netbox/netbox/scripts/NetBox_DNS_Tenancy.py \N \N f
5 \N 2025-05-15 17:38:12.701242+02 \N scripts /opt/netbox/netbox/scripts/AXFR_Importer.py \N \N f
6 \N 2025-05-15 17:38:18.898964+02 \N scripts /opt/netbox/netbox/scripts/DNS_IPAM_Updater.py \N \N f
7 \N 2025-05-18 10:59:11.872814+02 \N scripts /opt/netbox/netbox/scripts/NewSite.py \N \N f
\.
The hint to an easy fix is in the database dump: there’s a column "created"
that points to the modification time stamp of the script files.
A simple "touch"
(modify last changed file timestamp to “now”) to all script files will cause a re-indexing on the next start of netbox.
linux # touch scripts/*.py
After that your table should look like this:
COPY public.core_managedfile (id, data_path, data_synced, created, last_updated, file_root, file_path, data_file_id, data_source_id, auto_sync_enabled) FROM stdin;
5 \N 2025-05-15 17:38:12.701242+02 \N scripts AXFR_Importer.py \N \N f
6 \N 2025-05-15 17:38:18.898964+02 \N scripts DNS_IPAM_Updater.py \N \N f
3 \N 2025-05-15 17:33:20.00775+02 \N scripts NetBox_DNS_Exporter.py \N \N f
4 \N 2025-05-15 17:38:03.198915+02 \N scripts NetBox_DNS_Tenancy.py \N \N f
7 \N 2025-05-18 10:59:11.872814+02 \N scripts NewSite.py \N \N f