LinuxQuestions.org
Visit Jeremy's Blog.
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, 06:11 AM   #46
riahc3
Member
 
Registered: Dec 2002
Posts: 124

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, 09:42 AM   #47
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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-26-2008 12:23 AM
How do you make a usb drive bootable? comcastuser Linux - General 4 06-25-2007 03:19 AM
execute shell script when USB drive plugged in OneSeventeen Linux - Hardware 2 10-28-2005 11:27 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
can you make a usb drive bootable? citrus Linux - Newbie 4 05-16-2004 05:00 AM


All times are GMT -5. The time now is 04:33 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration