Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- RED='\033[1;31m'
- BLUE='\033[1;34m'
- GREEN='\033[1;32m'
- NC='\033[0m' # No Color
- function start() {
- p=`ps aux|grep openvpn|grep SUSE|grep -v grep|awk '{print $2}'`
- if [[ "$p" != "" ]]; then
- printf "${RED}OpenVPN is already running with process $p. Will not start again...${NC}\n\n"
- #ps aux|grep [o]penvpn
- else
- user=`cat /etc/openvpn/user.txt`
- printf "${GREEN}Starting OpenVPN for user ${user}. Please enter password...${NC}\n\n"
- sudo systemctl start [email protected]
- sleep 4
- for i in `seq 1 10`; do
- p=`ps aux|grep openvpn|grep SUSE|grep -v grep|awk '{print $2}'`
- if [[ "$p" == "" ]]; then
- printf "${RED}There is some problem starting the openvpn process${NC}\n\n"
- exit 1
- fi
- sleep 1
- done
- printf "${GREEN}OpenVPN running with pid=${p}${NC}\n\n"
- fi
- }
- function stop() {
- p=`ps aux|grep openvpn|grep SUSE|grep -v grep|awk '{print $2}'`
- if [[ "$p" != "" ]]; then
- ps aux|grep [o]penvpn
- printf "${GREEN}Killing process $p ${NC}\n\n"
- sudo kill -9 $p
- printf "${GREEN}Process OpenVPN with PID $p killed${NC}\n\n"
- else
- printf "${RED}Can't kill process. OpenVPN is not running${NC}\n\n"
- fi
- }
- function check() {
- p=`ps aux|grep openvpn|grep SUSE|grep -v grep|awk '{print $2}'`
- if [[ "$p" != "" ]]; then
- printf "${GREEN}OpenVPN process running with PID $p ${NC}\n\n"
- #ps aux|grep [o]penvpn
- else
- printf "${RED}No OpenVPN process runnign ${NC}\n\n"
- fi
- }
- if [[ "$1" == "stop" ]] || [[ "$1" == "s" ]] || [[ "$1" == "--stop" ]] || [[ "$1" == "-s" ]]; then
- stop
- elif [[ "$1" == "check" ]] || [[ "$1" == "c" ]] || [[ "$1" == "--check" ]] || [[ "$1" == "-c" ]]; then
- check
- elif [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "h" ]] || [[ "$1" == "help" ]]; then
- printf "${BLUE}usage${NC}: myvpn [stop|s|check|c] or [--stop|-s|--check|-c], with no args to start\n\n"
- else
- start
- fi
Advertisement
Add Comment
Please, Sign In to add comment