Ubus | OpenWRT
The ubus command line tool allows to interact with the ubusd server (with all currently registered services). It's useful for investigating/debugging registered namespaces as well as writing shell scripts. For calling procedures with parameters and returning responses it uses the user-friendly JSON format. Below is an explanation of its commands.
Simplified JSON System Board Information
Utilize the -S option with ubus call system board for a condensed JSON output detailing your OpenWRT system's specifications, including kernel version, model, and firmware details. This format is ideal for scripts and applications requiring parsed system information.
ubus -S call system board
{"kernel":"4.1.38","hostname":"OpenWrt","system":"ARMv7 Processor rev 1 (v7l)","model":"BCM963138","release":{"distribution":"OpenWrt","version":"Chaos Calmer","revision":"unknown","codename":"chaos_calmer","target":"brcm63xx-tch\/VANTW","description":"OpenWrt Chaos Calmer 15.05.1"}}
Standard JSON System Board Information
Invoke ubus call system board without options to receive a comprehensive JSON representation of your system's board information. This command outputs detailed data such as kernel version, hostname, system architecture, and firmware release details, providing a full overview of your device's specifications.
ubus call system board
{
"kernel": "4.1.38",
"hostname": "OpenWrt",
"system": "ARMv7 Processor rev 1 (v7l)",
"model": "BCM963138",
"release": {
"distribution": "OpenWrt",
"version": "Chaos Calmer",
"revision": "unknown",
"codename": "chaos_calmer",
"target": "brcm63xx-tch\/VANTW",
"description": "OpenWrt Chaos Calmer 15.05.1"
}
}
Verbose System Service Listing
Lists all system services in verbose mode, providing detailed insights into system functionalities and service parameters.
ubus -v list system
Retrieving Service Data
Fetches data from specified services, useful for diagnosing service states and configurations.
ubus call service get_data
System Board Information
Displays comprehensive information about the system's board, including model and firmware details.
ubus call system board
System Information
Provides detailed system information, crucial for system monitoring and troubleshooting efforts.
ubus call system info
Initiating System Upgrade
Triggers the system upgrade process, essential for maintaining system security and performance.
ubus call system upgrade
System Reboot
Commands the system to reboot, a critical operation for applying updates or troubleshooting.
ubus call system reboot
Generic System Call
Executes a generic call to the system, demonstrating the flexibility of ubus for system management.
ubus call system
Hostmanager Status
Checks the current status of the hostmanager, key for network device management.
ubus call hostmanager status
Retrieving Hostmanager Device Information
Acquires detailed information about devices managed by hostmanager, enhancing device administration.
ubus call hostmanager.device get
IGMP Proxy Interface Status
Queries the status of the IGMP proxy interface, important for multicast network management.
ubus call igmpproxy.interface status
Listing Execution Environments
Lists available execution environments, supporting container management and application isolation.
ubus call lcm list_execenvs
Network Device Status Inquiry
Query the status of network devices, essential for network troubleshooting and optimization.
ubus call network.device status
Service List Exploration
Navigate through the services running on your system, a fundamental step for system audit and management.
ubus call service list
IPTV Interface Examination
Examine the details of your IPTV interface, supporting robust digital entertainment system setups.
ubus call network.interface.iptv dump
List Detailed Info for LCM Packages
Examine the details of installed LCM packages
ubus call lcm list_packages
{
"packages": [
{
"Description": "",
"URL": "file:\/\/\/default.installed",
"execenv": "lxc_ee",
"Architecture": "arm_cortex-a9",
"Depends": "libc",
"Installed-Time": "1703066846",
"state": "installed",
"name": "core-lcm",
"version": "3.2.28+uci",
"Section": "utils",
"ID": "71cac8b1-24d8-4333-b980-f36c6c83a75f",
"Status": "install user installed",
"Installed-Size": "4574",
"Source": ""
},
{
"Description": "",
"URL": "file:\/\/\/default.installed",
"execenv": "lxc_ee",
"Architecture": "arm_cortex-a9",
"Depends": "libc",
"Installed-Time": "1703066850",
"state": "installed",
"name": "core-watchdog",
"version": "2.1.10+uci",
"Section": "utils",
"ID": "2b103504-a563-4e77-adf0-6b194badbfc1",
"Status": "install user installed",
"Installed-Size": "5168",
"Source": ""
}
]
}
Call wireless.radio.remote get via ubus
ubus -S call wireless.radio.remote get
This tries get only for objects that advertise it in ubus -v list
for o in $(ubus list); do
ubus -v list "$o" 2>/dev/null | grep -q '"get"' && echo "ubus -S call $o get"
done
If you want it to execute (not just print), replace echo with the call:
for o in $(ubus list); do
if ubus -v list "$o" 2>/dev/null | grep -q '"get"'; then
echo "== $o =="
ubus -S call "$o" get 2>/dev/null
fi
done
Only print callable get commands
for o in $(ubus list); do
if ubus -v list "$o" 2>/dev/null | grep -q '"get"'; then
ubus -S call "$o" get >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ubus -S call $o get"
fi
fi
done
Print callable commands for all methods
for o in $(ubus list); do
# extract method names from verbose description
methods=$(ubus -v list "$o" 2>/dev/null | sed -n 's/^[[:space:]]*"\([^"]*\)".*/\1/p')
[ -n "$methods" ] || continue
for m in $methods; do
ubus -S call "$o" "$m" >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ubus -S call $o $m"
fi
done
done
Show callable methods grouped per object (more readable)
for o in $(ubus list); do
methods=$(ubus -v list "$o" 2>/dev/null | sed -n 's/^[[:space:]]*"\([^"]*\)".*/\1/p')
[ -n "$methods" ] || continue
ok=""
for m in $methods; do
ubus -S call "$o" "$m" >/dev/null 2>&1 && ok="$ok $m"
done
[ -n "$ok" ] && echo "=== $o ===$ok"
done
Only call “safe” read-only methods
This version only executes methods that look like read operations:
allow: get status dump show info list read metrics ipv4leases ipv6leases cachedstatus board uptime (you can extend)deny: restart reload probe set delete add remove install uninstall start stop write modify* commit*
for o in $(ubus list); do
methods=$(ubus -v list "$o" 2>/dev/null \
| sed -n 's/^[[:space:]]*"\([^"]*\)".*/\1/p')
[ -n "$methods" ] || continue
for m in $methods; do
case "$m" in
# ---- denylist: state-changing / risky / hangs ----
restart|reload|probe|set|delete|add|remove|install|uninstall|start|stop|write|commit|apply|modify*|force*|reset*)
continue
;;
# ---- allowlist: read-only-ish ----
get|status|dump|show|info|list|read|metrics|ipv4leases|ipv6leases|cachedstatus|board|uptime)
ubus -S call "$o" "$m" >/dev/null 2>&1 && echo "ubus -S call $o $m"
;;
esac
done
done
This will show all callable data only (non-empty JSON)
for o in $(ubus list); do
methods=$(ubus -v list "$o" 2>/dev/null | sed -n 's/^[[:space:]]*"\([^"]*\)".*/\1/p')
[ -n "$methods" ] || continue
for m in $methods; do
case "$m" in
restart|reload|probe|set|delete|add|remove|install|uninstall|start|stop|write|commit|apply|modify*|force*|reset*)
continue
;;
get|status|dump|show|info|list|read|metrics|ipv4leases|ipv6leases|cachedstatus|board|uptime)
out="$(ubus -S call "$o" "$m" 2>/dev/null)" || continue
[ "$out" = "{}" ] && continue
[ -z "$out" ] && continue
echo "ubus -S call $o $m"
;;
esac
done
done
Resource(s)"