LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-22-2012, 05:11 AM   #46
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1

I was able to solve the problem with the help of someone from the team of the device (NetModule is the company: http://www.netmodule.com/ ).

The final working script is the following:

Code:
#!/bin/sh

# openvpn settings
SERVER="192.168.100.199"
PORT="1194"

# helpers
CLI="/usr/local/sbin/cli"
LOG="/usr/bin/logger -p local1.notice -t maintenance"

#some variables
OpenVPNConfFile=/etc/openvpn/tunnel0.conf
remoteLine="$(grep '^remote' "$OpenVPNConfFile")"
currentIP=$(echo "$remoteLine" | cut -d' ' -f 2)
currentPort=$(echo "$remoteLine" | cut -d' ' -f 3)

$LOG "running"

# make bottom led blinking in red
# echo "timer" > "/sys/class/leds/ind4:red/trigger"
# echo "500"   > "/sys/class/leds/ind4:red/delay_on"
# echo "500"   > "/sys/class/leds/ind4:red/delay_off"




# turn on solid red for bottom led (labelled IN2)
echo "1" > "/sys/class/leds/ind4:red/brightness"
echo "1" > "/sys/class/leds/ind4:green/brightness"

if [ $SERVER = $currentIP -a $PORT = $currentPort ]
then
	$LOG "openvpn is the same as the config on the usb. exiting..."
	echo "0" > "/sys/class/leds/ind4:red/brightness"
        echo "0" > "/sys/class/leds/ind4:green/brightness"
	exit 0
	
else


	# reconfigure openvpn
	$LOG "changing openvpn config (server=$SERVER, port=$PORT)"

	# $CLI set "openvpn.tunnel.0.server=$SERVER" "openvpn.tunnel.0.port=$PORT" || $LOG "unable to change config"

	sed -i "s/^remote.*/remote $SERVER $PORT/g" /etc/openvpn/tunnel0.conf

	# wait a bit
	sleep 3

	# restart openvpn
	$CLI restart "openvpn"

	# turn off bottom led again
	sleep 3
	echo "0" > "/sys/class/leds/ind4:red/brightness"
	echo "0" > "/sys/class/leds/ind4:green/brightness"

	$LOG "finished"

	exit 0

fi

Thank you very much to all that have helped here and the team at NetModule.
 
Old 08-22-2012, 08:42 AM   #47
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Glad to read that!
Mark the thread as solved, then
 
Old 08-23-2012, 02:14 AM   #48
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by 414N View Post
Glad to read that!
Mark the thread as solved, then
Did not know you could mark threads as solved, sorry.

Marked. Thanks for the help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make a USB drive bootable cccc Linux - General 2 10-25-2008 11:23 PM
How do you make a usb drive bootable? comcastuser Linux - General 4 06-25-2007 02:19 AM
execute shell script when USB drive plugged in OneSeventeen Linux - Hardware 2 10-28-2005 10:27 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
can you make a usb drive bootable? citrus Linux - Newbie 4 05-16-2004 04:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration