Well, that depends...
On a Fritzbox with current, unmodified firmware, you can't run a script because you won't get shell access. You might use modFS, Freetz or an AVM "inhouse" version of the firmware. If you can read German, you'll find plenty of information about each variant on this forum. In a nutshell, modFS extends the official firmware a little bit (in particular shell access) whereas Freetz offers quite a few additional packages (but imho too much effort if you just want to run a script). AVM's inhouse firmware builds contain Shell-in-a-box (SIAB) and you don't have to build a firmware image yourself, but they might contain bugs. What's most suitable for you depends on the Fritzbox model you have and the firmware available for it as well as your computer skills (especially Linux).
Maybe you could run a script for checking the connection status on the device itself, but as you haven't provided any information about that device, my crystal ball remains opaque for the time being.