-5

So I'm on Hack The Box and at times the VPN isn't actually connected to a host after being away or doing some other tasks that may mess with the connection. I just need help making a bash script that will.

  1. ping a previously specified IP address.
  2. Run the command again to restart the VPN
  3. Ping the IP address in the background persistently or every few seconds and give a message if the connection is lost.
  • What have you tried so far? You might get better help if you can show what you've attempted. – axwr Dec 22 '20 at 22:36
  • StackOverflow is not a free coding service where you can publish rough specifications and get developers to code that to you for free. StackOverflow is a community where developers helps each-other help themselves with sharing knowledge. Your post asks for code and does not show any effort to solve it. – Léa Gris Dec 22 '20 at 22:51

1 Answers1

2

This should could you started:

#!/bin/bash

ip=...
interval=30

function restart_vpn() {
  ...
}

while :
do
  ping -c $ip > /dev/null || restart_vpn
  sleep $interval
done

Not sure what "Hack The Box" is but you might be able the determine the state of your vpn in a more direct way than via ping. For instance on Linux, you might get an interface, and you can check on that with ip link.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38