mercredi 21 janvier 2015

Connecting 3 OpenVPN connections through a shell script


For work I need to connect to 3 different OpenVPN connections every day. I'm using a shell script to speed this up, but I feel like it could be done better.


Currently my script is:



#!/bin/bash

cd ~/vpns
sudo openssl aes-128-cbc -d < login.conf.aes > login.conf

cd ~/vpns/live_vpn
(sudo openvpn --config config.ovpn --auth-user-pass ~/vpns/login.conf) &
cd ~/vpns/mgmt_vpn
(sudo openvpn --config config.ovpn --auth-user-pass ~/vpns/login.conf) &
cd ~/vpns/test_vpn
(sudo openvpn --config config.ovpn --auth-user-pass ~/vpns/login.conf) &

cd ~/vpns
sleep 20
wipe -f login.conf


Openssl decrypts a file containing the username and password for the connections, which is then wiped after the connections are established.


This works but has some problems:



  • The repeated cds seem inelegant.

  • I hope the sleep command (which gives openvpn time to use the decrypted login file) can be replaced so that the wipe occurs as soon as the connections are established.

  • I've called sudo above the openvpn lines as otherwise they seem to 'pile up' on the shell and give no opportunity to enter the password.


My question is: What would be a better way to achieve this?



Aucun commentaire:

Enregistrer un commentaire