0

I am using protonvpn.

My servers looks like:

UK#13
US-VA#2
US-CA#1
US-CA#2
US-NJ#9

To switch to a server, I have to use protonvpn c UK#13.

I want to cycle through the vpn servers in this list sequentially after every one hour infinitely.

In other words, after 1st hour it will run protonvpn c UK#13

after 2nd hour it will run protonvpn c US-VA#2

after 3rd hour it will run protonvpn c US-CA#1

after 4th hour it will run protonvpn c US-CA#2

after 5th hour it will run protonvpn c US-NJ#9

after 6th hour it will run protonvpn c UK#13

after 7th hour it will run protonvpn c US-VA#2

after 8th hour it will run protonvpn c US-CA#1

.....

How can I do that?

1
  • 1
    What have you tried on your own? Where are you stuck? This looks like a simple for x in $servers task. – Panki Mar 1 at 14:24
1

You could also do it with a simple bash script

#!/bin/bash

sites=("UK#13" "US-VA#2" "US-CA#1" "US-CA#2" "US-NJ#9")
while true;
do
  for site in ${sites[@]};
  do
    echo "Connecting to $site"
    sleep 1
  done
done

Change sleep 1 to sleep 3600 and add in your protonvpn command rather than the echo.

0
1

Simple switch script and a config file run in cron or systemd-timer should suffice.

#!/usr/bin/env bash

set -euo pipefail

SWITCHFILE='/tmp/switch'

switch_to="$(head -1 $SWITCHFILE)"
sed -i '1d' "$SWITCHFILE"
echo "$switch_to" >> "$SWITCHFILE"
protonvpn c "$switch_to"

config file:

UK#13
US-VA#2
US-CA#1
US-CA#2
US-NJ#9

Here is the explaination of the scripts working. There is a config file (put it somewhere safer than /tmp) that contains a list of servers you want to cycle through. The script reads the first one and saves it to $switch_to. Then it deletes this first line (thats the sed command) and appends it to the end of the file. Then it calls protonvpn as requested to switch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.