Modern linux distributions usually come with some kind of network manager installed by default. The most common is NetworkManager. I have also used wicd in the past. But here is the way to make this work using cli tools only.
Why do this? One reason is that the cli way is more flexible. The graphical network interface managers do not always allow you to have multiple devices configures. At least I could not figure out how to make this happen. Also, doing this the cli way means typing in vi rather than clicking.
First, install wpasupplicant if you have wireless interfaces:
sudo apt install wpasupplicant
Now modify /etc/network/interfaces to inlude all of the interfaces you plan to use. Here is an example:
Since this file will contain login credentials for your wireless network, you may wish to also chmod 600 /etc/network/interfaces.
Now to the monitoring script. Modify it to reflect the ip addess of your router as well as your interfaces.
Just save this as something like /root/netmgr.sh, chmod +x, and then schedule it in root's crontab.