Hi all. Is there a script where I can ping www.google.com every 5 seconds as a heartbeat? My VPN gets shaped if there is no traffic.
Hi all. Is there a script where I can ping www.google.com every 5 seconds as a heartbeat? My VPN gets shaped if there is no traffic.
#!/bin/sh
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
sleep 5s
ping google.com -c1
cru a ping_script "* * * * * /jffs/scripts/ping_script"
echo 'cru a ping_script "* * * * * /jffs/scripts/ping_script"' >> /jffs/scripts/init-start
echo "#!/bin/sh" > /jffs/scripts/init-start
echo 'cru a ping_script "* * * * * /jffs/scripts/ping_script"' >> /jffs/scripts/init-start
chmod 0755 /jffs/scripts/init-start
Cron has down to the minute triggering, so you would need to create a script that runs for 1 minute pinging google 12 times during its execution.
Ping Script that should saved as /jffs/scripts/ping_script:
Code:#!/bin/sh ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1 sleep 5s ping google.com -c1
Cron Entry:
Code:cru a ping_script "* * * * * /jffs/scripts/ping_script"
---
The above would only be active until you reboot the router.
To make it persistant, you would have to add a cron "ping_script" entry upon reboot into "init-start"
if /jffs/scripts/init-start already exists and is configured to accept sh execution
Code:echo 'cru a ping_script "* * * * * /jffs/scripts/ping_script"' >> /jffs/scripts/init-start
if /jffs/scripts/init-start does not exist / is not configured
Code:echo "#!/bin/sh" > /jffs/scripts/init-start echo 'cru a ping_script "* * * * * /jffs/scripts/ping_script"' >> /jffs/scripts/init-start chmod 0755 /jffs/scripts/init-start
( Why not ping bing?)
This is so very helpful. who should I ping. akamai, bing or google. just curious. the idea is just to keep it alive.
That was just a joke. Ping whoever you want.
I know.
Also how can I tell if the script is pinging? Is there a way to test?
ps | grep "ping_script"
I tried to see if netstat would show the connection but it wouldn't.
The next easiet step would be to check ps (task manager) if your created script is currently running via this command
Code:ps | grep "ping_script"
To really be sure, it is possible to setup an iptable rule entry to log all outgoing connections opened by the router itself into the system log and then manually analyze that.
Or alternatively, I would think if I can ping a ping logger website that would enlist a hit or a local ping and monitor a hit then that would suffice too?
#!/bin/sh
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
sleep 5s
logger -t "ping_script" -s "pinging google.com"
ping google.com -c1
There are many ways to achieve the same solution so use whatever you feel comfortable with.
eg simply logging to system log upon execution or once per ping would also work aswell
Code:#!/bin/sh logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1
Welcome to linux! This router taught me so much. Linux is so flexible and open its insane!
There are many ways to achieve the same solution so use whatever you feel comfortable with.
eg simply logging to system log upon execution or once per ping would also work aswell
Code:#!/bin/sh logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1
Welcome to linux! This router taught me so much. Linux is so flexible and open its insane!
There are many ways to achieve the same solution so use whatever you feel comfortable with.
eg simply logging to system log upon execution or once per ping would also work aswell
Code:#!/bin/sh logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1 sleep 5s logger -t "ping_script" -s "pinging google.com" ping google.com -c1
Welcome to linux! This router taught me so much. Linux is so flexible and open its insane!
Thank you so much for your help, however, the ping on the router didn't cause the VPN to remain alive. This could happen due to a few issues in my opinion such as.
ping on google.com is getting routed through the internet and not through the VPN as it was on the laptop.
Is there a way to get the output of the ping to the logger.? is the cron job using the same route as when the command is being run on terminal?
for example if I ping www.google.com on local network, I'll get 10ms in response. however when its on VPN it will give a response of 189ms. hence I know its going through the vpn.
Alternatively do you suggest to increase the size of ping packets?
The ping will be exactly the same as you SSH'ing into the router and preforming it manually. So the answer completely depends on how you configured the client.
I think the real issue here is your VPN provider. I've never heard of any provider closing a session or throttling it due to inactivity over a 5s period. Sounds like its time to start shopping for a new VPN.
Log onto the router through SSH and issue the ping command interactively. Then you can see what the response time is.for example if I ping www.google.com on local network, I'll get 10ms in response. however when its on VPN it will give a response of 189ms. hence I know its going through the vpn.
Log onto the router through SSH and issue the ping command interactively. Then you can see what the response time is.
Try ping -I tun1X (or whatever interface name astrill uses)I did some indepth tests on the router to see the route with and without VPN and concluded that the router was NOT going through the VPN. I have not done an exclusion rule on the VPN Applet and the router is now routing through the vpn tunnel. I have restored the nightly restart as well. Will give it another go and hopefully "fingers crossed" will be able to report some success tomorrow morning.
I have also changed the ping to once in 20 seconds and the ping ip to 8.8.4.4 instead of a dns resolution of google.com
Thats a great suggestion. I'll try to figure out the tunnel and test this tomorrow. I hope this setup will work. Will know in a few hours.Try ping -I tun1X (or whatever interface name astrill uses)
Try ping -I tun1X (or whatever interface name astrill uses)
Thread starter | Title | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Questions Regarding acme.sh Cron Job Setup and Directory Linking | Asuswrt-Merlin | 1 |
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!