EvilZone
Programming and Scripting => Scripting Languages => : m0l0ko September 14, 2013, 02:03:49 AM
-
Don't know if daemon is the right word, I want to make a program that will always be running in the background, waiting for something to happen. In this case I want it to wait for me to get disconnected from my VPN, then it will reconnect me. Basically, I need it to make sure I am always connected to a VPN. What kinda programming concepts do I need to know for this? Can this be done with bash scripting? If not, I suppose I'll use java.
-
I'm not expert on this, but java is not the right tool to use. I'd recommend C++, but try bash first.
-
Have a look here: http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/ (http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/)
They do it entirely with bash and also explain how to run it automatically after login in the background.
It is no special programming concept, just check for a variable and sleep for 30 seconds, then check again and sleep for 30 seconds.
-
I'd recommend C++, but try bash first.
C++ for a daemon?
Anything beyond C is overkill, especially if he's in a *nix environment.
-
Have a look here: http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/ (http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/)
They do it entirely with bash and also explain how to run it automatically after login in the background.
It is no special programming concept, just check for a variable and sleep for 30 seconds, then check again and sleep for 30 seconds.
Thanks. I didn't think of just putting it on a sleep loop. Does adding the script to your .profile directory make it run as a background process?
-
Thanks. I didn't think of just putting it on a sleep loop. Does adding the script to your .profile directory make it run as a background process?
No. That just starts it after you logged in. The & in the end of the command makes it work in the background.
-
It works. Thanks a lot. Now I'm trying to think of a way to switch it off and on when I need to. I tried making an environment variable VPN_SWITCH and set it to either on or off, but the script can't read environment variables that I set in another instance of bash like that.
-
Just shut down the program or start it again?
-
I can't seem to kill the process:
horse@box:~$ ps -e | grep 'vpn'
2405 ? 00:00:00 vpn.sh <defunct>
horse@box:~$ kill 2405
horse@box:~$ ps -e | grep 'vpn'
2405 ? 00:00:00 vpn.sh <defunct>
BTW why does it say <defunct> beside the process name?
-
I can't seem to kill the process:
BTW why does it say <defunct> beside the process name?
Its a so called 'zombie' , it probably finished but is still around :)
-
Have you tried kill -9 ?