Disconnect then connect Wifi Client script on Slate (GL-AR750S-Ext)

Hello everyone,

i need to disconnect sometimes from WiFi Client and reconnect it again if internet doesnt works anymore.

I write a script on my raspberry pi but it doesnt works on my GL-AR750S.

it checks via cron every minute the ping if internet is down then it disconnect and connect wifi again.

here is the code:


The IP for the server you wish to ping ( is a public Google DNS server)


Only send two pings, sending output to /dev/null

ping -c2 ${SERVER} > /dev/null

If the return code from ping ($?) is not 0 (meaning there was an error)

if [ $? != 0 ]
# Restart the wireless interface
ifconfig wlan0 down
sleep 15
ifconfig wlan0 up

what i do wrong?

I am running something similar, within a loop instead of using cron, and my if statement looks like:

  ping -q -c 1 $SITE
  if [ "$?" -eq 0 ]
      #saw remote site, so all is good
      # do something!

You may want to try β€œ-ne” instead of β€œ!=” in your β€œif” statement.

Also, change:


As bash is normally not available.

1 Like

Thank you eric it works!

here is my code if some one need it in future (saved under /usr/bin/wifi_rebooter.sh):


ping -c2 ${SERVER} > /dev/null
if [ $? -ne 0 ]
   echo "Offline"
   ifconfig wlan-sta down
   sleep 25
   ifconfig wlan-sta up
   echo "Online"

then make it executable:

chmod +x /usr/bin/wifi_rebooter.sh

Now set a cron in under System -> Scheduled Tasks i added this line to check every 2min if internet connection exists if not restart wifi client:

*/2 * * * * /usr/bin/wifi_rebooter.sh

Now go to System -> Startup and restart cron.

1 Like