Script for rebooting router if mwan3 is disconnected

Hello
I am not guru in Linux
Maybe some could help me with script how can I reboot router if any interfaces was disconnected?
I think I have to chande the contents of /etc/hotplug.d/iface/16-mwancustom

Available variables:

$ACTION
      <ifup         Is called by netifd and mwan3track
      <fdown       Is called by netifd and mwan3track
      <connected    Is only called by mwan3track if tracking was successful
      <disconnected Is only called by mwan3track if tracking has failed
 $INTERFACE	Name of the interface which went up or down (e.g. "wan" or "wwan")
 $DEVICE	Physical device name which interface went up or down (e.g. "eth0" or "wwan0")

I think script would be following:
!/bin/sh

if [ "$INTERFACE" = "wan1" || "$INTERFACE" = "wan2" ]; then
if [ "$ACTION = "ifdown" ]; then
	sleep 70 && touch /etc/banner && reboot
fi
fi
exit 0

Am I right?

Reboot is a pretty brutal way to handle a re-initialization problem.

Before saying if that script is "right" would you step back a bit and describe the problem you're trying to resolve?

I’m using two LTE modems with mwan3
Sometimes connect is broken on any modem.
I get lost ping firstly and then offline status of the interfaces wan1 or wan2
I don’t know reasons of that because system and kernel Logs contains nothing about it
I reboot router linksys wrt3200 and the both modems are worked fine again

A post about USB device reset might be usefull in your case.

Thanks
I've explored info, installed package and remake my script:)
info from usbreset:

Devices:
  Number 002/002  ID 1a40:0201  USB 2.0 Hub [MTT]
  Number 002/003  ID 0f3d:68aa  AirCard 320U
  Number 002/004  ID 12d1:1506  MOBILE
!/bin/sh

if [ "$ACTION = "ifdown" && "$INTERFACE" = "wan1"]; then
usbreset 002/003
else
usbreset 002/004 
fi
exit 0
1 Like

Hi
maybe someone can help me and check script:

if [ "$ACTION" = "disconnected" ] ; then
    If  [ "$INTERFACE" = "wan1" ]; then
usbreset 002/003
else
usbreset 002/004
  fi 
fi
exit 0

thanks

Your second if has a capital i. That doesn 't work

Can’t help but...

Here

https://openwrt.org/docs/guide-developer/write-shell-script

You find a link to shell script checker

https://www.shellcheck.net/