This link has a similar script, if you are interested:

https://wiki.openwrt.org/doc/recipes/ap_sta