Jump to content
Mysticle31

Script to Ping Device, and Restart WIFI plug if ping fails. Can this be in a docker?

5 posts in this topic Last Reply

Recommended Posts

Posted (edited)

I have a perhaps unusual network typology, pictured.  https://imgur.com/RXVgMrF

 

What happens is Router B often randomly looses connection (especially after long periods of no-use [eg. overnight]).  

 

To solve this problem all I have to do is reboot Router B, wait 2-3 minutes, and Router C will be connected again.  Sometimes Router C stops trying to get an address on the WAN port and I have to log in and tell it to connect.  

 

What I'm after is a script where, from Unraid (or Router C) I ping Router A every minute.  This might in-and-of-itself keep the connection up.  If the ping fails, kill power to the WIFI switch that powers Router B (I can handle that part), then ssh into Router C and tell it to connect (I can handle that too).  

 

What I'm not sure how to do is trigger an if statement for if the ping fails.  I also dont know how to make the script run on Unraid at system boot in the background.  Can I put something like this in a simple docker that starts at startup?  That way I can switch it on and off easily.  Is there a basic lightweight docker with command line network utilities only?

 

How would I make this? Any examples?

Edited by Mysticle31

Share this post


Link to post

Install User Scripts plugin from Community Apps. It can schedule an sh script.

 

You can do it on a docker but it would be more complicated.

Share this post


Link to post

Perfect!  User Scripts.  That opens the door for me to do all kinds of things.  Thanks!

 

Any idea what the best way is to write a script to monitor output from ping?  Whats the best/easiest way. 

 

Other than having one script run the ping command continuously, printing the output to a file.  Then another script to read the contents of the file and look for "bad" "disconnected" whatever terms ping uses.  Then another script to delete the file every month or so.... complicated. 

Share this post


Link to post
24 minutes ago, Mysticle31 said:

Perfect!  User Scripts.  That opens the door for me to do all kinds of things.  Thanks!

 

Any idea what the best way is to write a script to monitor output from ping?  Whats the best/easiest way. 

 

Other than having one script run the ping command continuously, printing the output to a file.  Then another script to read the contents of the file and look for "bad" "disconnected" whatever terms ping uses.  Then another script to delete the file every month or so.... complicated. 

Can’t you simply monitor the exit status of the ping command?    As I understand it 0 means success, anything else means failure.

Share this post


Link to post

I did something like this years ago, back then I had an unstable fiber modem, which just stopped passing anything through. To restart that, I wrote some code in arduino, and flashed it to a Sonoff. It would then try to access google.com, and if it had failed connecting for a few minutes, it would kill power to the modem, wait 15 seconds, then turn it back on. After that it would give it 5 minutes to start up and get connection, if it didnt, it would be power cycled again.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.