How to get the wi-fi connection status from terminal?
You do not need a script for tuning the WiFi on and connecting you, the OS X system does that already for you. If you look in Console (look for line containing Airport) and the lines after that will show it in action.
Best is if you could publish that log in here to see why is it not working for you.

Here are some choices for you:


If you want a Scrip to continuously test if you are connected you could use this:

repeat
    try
        do shell script "ping -c 5 google.com"
    on error
        display dialog "You are not connected to the internet"
    end try
end repeat
One of the simplest Terminal commands to see if you are connected and all connections that are active is the Netstat.
To see the details of your current connection use Airport-I in Terminal.
Now if you want to use the Terminal to connect to your WiFi use following:


Manually connect to WiFi

Turn On

networksetup -setairportpower en0 on


Turn OFF networksetup -setairportpower en0 off

Find

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan


Connect

networksetup -setairportnetwork en0 WIFI_SSID_I_WANT_TO_JOIN WIFI_PASSWORD


If you do not know it use the Find the SSID- BSSID

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s



Finlay, if you do this frequently create a script in Apple Script app.


Save the following apple script as application. Pull it to your dock for fast access.

--
-- Toggle Airport Power On and Off
--
if (offset of "On" in (do shell script "networksetup -getairportpower en0")) &gt; 0 then
    do shell script "networksetup -setairportpower en0 off"
else
    do shell script "networksetup -setairportpower en0 on"
end if