Hawkes:
In both cases the timing is not critical, so it would be sufficient to have a daemon checking the situation every minute.
I'll leave this part as an exercise to the reader.
But if you get something working, I'd love to see it as it may help me.
I would be glad if someone could provide a short example as I'm not that much into configuring wifi interfaces using config files 
I've created different configuration files in the past, and manually copied them in place to change WiFi modes. I just wrote a very simple script to automate switching modes. Here's basically what I did:
- Go into the Yun's advanced configuration web pages, set up the first mode as desired, then click "Save and Apply."
This creates the configuration file /etc/config/wireless
- From the SSH command line, copy the configuration file to a new file.
I put it on the SD card at /mnt/sda1/wireless/ but it doesn't really matter where.
Give it a meaningful name.
- Go back into the Yun's advanced configuration web pages, and set up the the next mode as desired. Click "Save and Apply."
- From the SSH command line, copy the configuration file to a new file.
- Create the mode change script (listed below) and make it executable (chmod +x)
The script to change modes: /mnt/sda1/wireless/changeWiFi
#!/bin/ash
# Script to change the WiFi configuration
# Parameter is the name of the new WiFi configuration file
# Wifi interface is brought down, the new configuration file
# is copied into place, then the WiFi is started again.
# Stop the current WiFi configuration
wifi down
# Copy the new configuration file into place
cp $1 /etc/config/wireless
# Start the new WiFi configuration
wifi
Now, whenever you want to change modes, execute the change script file giving the name of the saved configuration as a parameter. You can call this script from the Arduino side using the Bridge's Process class, or if you write your network monitor daemon on the Linux side, you can call it directly from your daemon.
An example:
The saved client mode configuration file: /mnt/sda1/wireless/wireless.client
config wifi-device 'radio0'
option type 'mac80211'
option hwmode '11ng'
option path 'platform/ar933x_wmac'
option htmode 'HT20'
list ht_capab 'SHORT-GI-20'
list ht_capab 'SHORT-GI-40'
list ht_capab 'RX-STBC1'
list ht_capab 'DSSS_CCK-40'
option disabled '0'
option channel 'auto'
option country 'US'
option txpower '16'
config wifi-iface
option device 'radio0'
option network 'lan'
option mode 'sta'
option encryption 'psk2'
option key 'ClientModePassword'
option ssid 'ClientModeSSID'
The saved access point mode configuration file: /mnt/sda1/wireless/wireless.AP
config wifi-device 'radio0'
option type 'mac80211'
option hwmode '11ng'
option path 'platform/ar933x_wmac'
option htmode 'HT20'
list ht_capab 'SHORT-GI-20'
list ht_capab 'SHORT-GI-40'
list ht_capab 'RX-STBC1'
list ht_capab 'DSSS_CCK-40'
option disabled '0'
option channel 'auto'
option country 'US'
option txpower '16'
config wifi-iface
option device 'radio0'
option network 'lan'
option encryption 'psk2'
option ssid 'ApModeSSID'
option mode 'ap'
option key 'ApModePassword'
Changing modes: (using SSH command line)
[b][color=blue]root@Arduino:/# [/color][color=red]/mnt/sda1/wireless/changeWiFi /mnt/sda1/wireless/wireless.client[/color][/b][color=blue]
Successfully initialized wpa_supplicant
[b]root@Arduino:/# [/b][/color][color=red][b]pretty-wifi-info.lua[/b][/color][color=blue]
Current WiFi configuration
SSID: ClientModeSSID
Mode: Client
Signal: 0%
Encryption method: -
Interface name: wlan0
Active for: 0 minutes
MAC address: 90:A2:DA:F0:32:D2
RX/TX: 0/0 KBs
[b]root@Arduino:/# [/b][/color][color=red][b]/mnt/sda1/wireless/changeWiFi /mnt/sda1/wireless/wireless.AP[/b][/color][color=blue]
Configuration file: /var/run/hostapd-phy0.conf
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
ACS: Automatic channel selection started, this may take a bit
wlan0: interface state COUNTRY_UPDATE->ACS
wlan0: ACS-STARTED
wlan0: ACS-COMPLETED freq=2442 channel=7
Using interface wlan0 with hwaddr 90:a2:da:f0:32:d2 and ssid "ApModeSSID"
wlan0: interface state ACS->ENABLED
wlan0: AP-ENABLED
[b]root@Arduino:/# [/b][/color][b][color=red]pretty-wifi-info.lua[/color][/b][color=blue]
Current WiFi configuration
SSID: ApModeSSID
Mode: Master
Signal: 0%
Encryption method: WPA2 PSK (CCMP)
Interface name: wlan0
Active for: 0 minutes
MAC address: 90:A2:DA:F0:32:D2
RX/TX: 0/0 KBs
[b]root@Arduino:/#[/b]
[/color]
As an alternative, you could write your "change mode" script to issue all of the UCI commands to change each individual wireless configuration item (mode, SSID, password, etc.) But while my copy file method uses a bit more disk space to store copies of the configuration files, on the whole I think it's a much simpler method and easier to maintain. In the future, if you want to update any of the configurations, it's a simple matter of starting that configuration, using the web interface to make and apply the changes, and then saving a new copy of the configuration file. That's a lot simpler than editing the script file and changing all of the UCI commands! I think this is a much more maintainable solution.
Good luck!