How to keep Yun connected to WIFI

Thanks Sonnyyu,

Im very new to linux generally. Can I please check my understanding of the following

nano /etc/rc.local               // OK So this command edits the rc.local which appears to be a file which runs at boot time
#wifi-live-or-reset                        // This appears to be a daemon which monitors whether the wifi is up. 
                                                            // Does this same daemon constantly monitor the status of the wifi during runtime and if it
                                                           // drops reverts back to AD hoc mode. Or does it only run on boot to check for the presence of WIFI

Now comes the bit I am totally stuck on. Your code snippet:

...
if [ $count -eq 0 ]; then
	# no internet do clean job, kill bridge  and your script
	/sbin/wifi
	/etc/init.d/network  restart
else
...

Appears to come from some code on the link you kindly provided. I've tried to comment it to test my understanding but I dont understand the syntax of scripts so any correction is welcome

#!/bin/sh                                                                                                                                              // Use the sh shell
HOSTS="8.8.8.8"                                                                                                                                // Declare HOST to use googles public DNS
ping_attempts=1                                                                                                                               // Set ping attempts to 1
sleep_time=10                                                                                                                                    // Set initial time between tests to 10 seconds

while true                                                                                                                                            // While whats true? I dont understand
do                                                                                                                                                          // Start a do loop
        count=$(ping -c $ping_attempts $HOSTS | awk -F, '/received/{print $2*1}')    // Ping 8.8.8.8 once. Get the result 0 = down 
                                                                                                                                                              // 1 would = up
        #echo $count                                                                                                                          // I assume this isnt needed. Just user feedback
        if [ $count -eq 0 ]; then      # IF INTERNET DOWN                                                      // If count = 0 internet is down

                /sbin/wifi                                                                                                                         // Not sure why no switch here. Would
                                                                                                                                                            // have expected an argument
                                                                                                                                                            // i.e      /sbin/wifi down
	        /etc/init.d/network  restart                                                                                     // Restart the network
                                                                    
        else                                            # IF INTERNET UP                                                               // if count = 1 internet i up
        fi                                                                                                                                                   // End of the if
        sleep  $sleep_time                                                                                                                 // Put the calling thread to sleep for 10 seconds
done                                                                                                                                                   // End of do loop

Where does this code go, bearing in mind I have no experience of linux. It doesnt makes sense to me to put it in the rc.local as if I understand correctly that is only run at startup to start the #wifi-live-or-reset

Hope you can help with a bit more details on how to implement this in linino. Im sure newbies will ask this question again in future so it would be nice to get it pinned down.

Thanks

Chris