automatic connect y disconnect

This forum is for general conversation and user-user networking.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
jhoelperaltap
OpenVpn Newbie
Posts: 1
Joined: Mon May 06, 2024 6:46 pm

automatic connect y disconnect

Post by jhoelperaltap » Mon May 06, 2024 6:59 pm

Greetings, I would like to know if there is a way to program openvpn to connect at a specific time and disconnect, for example, I want it to remain disconnected from 11:00 p.m. until 1:00 a.m. the next day but that this process does it continuously.

robertpackard
OpenVpn Newbie
Posts: 1
Joined: Mon Jun 24, 2024 4:29 am

Re: automatic connect y disconnect

Post by robertpackard » Mon Jun 24, 2024 4:34 am

Hello,
Yes, it is possible to program OpenVPN to connect and disconnect at specific times using scripting or scheduling tools available in your operating system. Here's a general approach you can follow:

1. Write a script that includes the commands to connect and disconnect OpenVPN. The specific commands may vary depending on your operating system and OpenVPN configuration. Here's an example script using Bash on Linux:

Code: Select all

bash
#!/bin/bash

# Disconnect OpenVPN
sudo openvpn --config /path/to/openvpn-config.ovpn --auth-user-pass /path/to/credentials.txt --auth-nocache --reneg-sec 0 --daemon

# Sleep for the desired duration (in seconds)
sleep 7200  # 2 hours

# Connect OpenVPN
sudo killall openvpn
In this example, the script disconnects OpenVPN, sleeps for 2 hours (7200 seconds), and then reconnects OpenVPN.

2. Set up the scheduling: Depending on your chosen tool, you can schedule the script to run at specific times. For example, using cron on Linux, you can edit the crontab file by running crontab -e and add an entry like this:

Code: Select all

basic
0 23 * * * /path/to/script.sh
This cron entry will execute the script at 11:00 p.m. every day.

3. Make the script executable: Ensure that the script has the appropriate permissions to execute. You can use the chmod command to set the executable permission. For example:

Code: Select all

bash
chmod +x /path/to/script.sh
With this setup, the script will automatically connect OpenVPN at 11:00 p.m., disconnect it after 2 hours, and repeat the process continuously.

Post Reply