OpenWrt Forum Archive

Topic: Need assistance with automating a timed script

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

How do I get a script to run that depends on a ping failing - where can I read up on this?

Need to restart wifi interface if a ping fails and then click the i agree on a hotspot page.

Thank You

you did not mention what are you trying to ping - lan or wan interface. I am taking as wan so script should be like below and make it run from crontab every 1 minute

if ping -q -c 2 www.google.com; then
                echo "LinkUp" > /tmp/link
else
                 wifi reload
                 curl --data " " <http://your hotspot html page>

fi

for auto clicking in hotspot page you will need to use curl command but before that you will need to identify variables in hotspot page by viewing its source html file. Once you have figured it out then place the below command

curl --data " " <http://your hotspot html page>

Here is the code I use on remote systems to make sure if I cut myself access It will reboot and restore access.
If 3 consequent ping attempts fail it executes payload.

#!/bin/sh

#uncomment trap if you want it to not die on ssh session end
#trap "" SIGHUP SIGINT

# which ip to test
IP=192.168.1.1

c=0

while true
do
 ping -c 1 -W 1 $IP >/dev/null 2>/dev/null || {
  c=$(( $c+1 )) 
  echo ping failed n=$c
  [ $c -ge 3 ] && {
   echo fatal shit
   # PUT HANDLER HERE
   reboot
   break
  }
  sleep 3
  continue
 }
 c=0
 echo ping ok
 sleep 5
done

(Last edited by bolvan on 27 Nov 2016, 10:07)

yes wan failure
ok next question how do i get this code in to openwrt - telnet or the web gui?

via telnet need to create a file and copy the contents in it.
then change permissions by command " chmod 777 <filename>"
and then try to run script once manually

The discussion might have continued from here.