[SOLVED] Run a custom script as a cronjob with specific WAN interface?

I’m planning to buy GL-MT3000 to use it’s multi-wan feature with a Huawei E3276 and a 4G chip in my country as a fallback.

I can buy a sms chip of 150GB, but I need to use it at least once in a month or my credits will expire.

I would like to know if it’s possible, by scripting in a cronjob, download everyday a 1mb file from somewhere using this wan. Should I be reading [OpenWrt Wiki] Write shell scripts in OpenWrt and [OpenWrt Wiki] Scheduling tasks with cron to accomplish this task?

You can use the curl command to download from certain WAN, from repeater interface:

curl -I --interface wlan-sta0 http://example.com/file-to-download

And integrate this into your shell and crontab configs. That should work.

1 Like

Trying in a macbook with a valid interface:

curl -I --interface en0 https://www.africau.edu/images/default/sample.pdf -O

Trying with an invalid interface:

curl -I --interface wlan-sta0 https://www.africau.edu/images/default/sample.pdf -O
curl: (45) Couldn't bind to 'wlan-sta0'
# Returns 1, showing it failed

Trying with a valid interface, but offline:

curl -I --interface en0 https://www.africau.edu/images/default/sample.pdf -O                                                                                                                                         
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: www.africau.edu
# Returns 1, showing it failed

It seems robust enough if the curl from openwrt have the --interface feature. I can integrate some logic to correctly monitor this using https://healthchecks.io notifications.

1 Like

If somehow curl in openwrt doesn’t have this feature, another solution is to create a script that uses ubus call. In a script:

  • Use ubus call to call down all interfaces;
  • Use ubus call to call up only the 4G interface;
  • Download the file;
  • Call down all the interfaces and call it up all again.

…or, create a hotplug script (docs/guide-user/base-system/hotplug#iface) that downloads the file and put the commands above in a cron. It depends on preference.

This is currently working on the Slate and used for speed test: SmoothWAN-feeds/wanspeedtest at main · SmoothWAN/SmoothWAN-feeds · GitHub