Wednesday, 20 September 2017

Grandstream VOIP phones - Mass reboot script

Here is a little snippet of code that I've written to reboot all Grandstream phones on a VOIP system (Asterisk).
It's very simple, it queries the Asterisk running process for all extension numbers, then uses the SIP NOTIFY method to send a reboot to the phones.

I've tested this on GXP1620 handsets so far and it works great, the phone reboots almost immediately. I've added a 25 second sleep in between each phone reboot, the idea is not to reboot your entire estate at the same time, leaving no phones available. Change that as required. My plan is to schedule this on a cron job overnight anyway, but still spacing reboots out seems to be more sensible.

Caveats: The script simply grabs all extensions and iterates through them all, so it'll try extensions that aren't Grandstream, or aren't phones (e.g. trunks) but those will just get ignored anyway.

#!/bin/bash
EXTENSION_LIST=`asterisk -rx "sip show peers" | cut -d "/" -f 1 |cut -d " " -f 1 | grep -o '[0-9]*'`
while read -r line; do
    echo "Rebooting extension: $line ..."
asterisk -rx "sip notify spa-reboot $line"
echo "(sleep)"
sleep 25
done <<< "$EXTENSION_LIST"

It's very simple and rough but will do the job!

No comments:

Post a Comment