Ubuntu 11.04 64bit
2.6.38-13-generic #56-Ubuntu SMP Tue Feb 14 12:39:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Using the Gnome desktop interface, and bash.
My skill level with Bash:
Somewhere between beginner and intermediate. I understand most of the basics, but not how to use all the basic concepts together very well.
If VPN is active or inactive
If VPN is inactive, stop all programs that depend on the VPN being active.
If I start the programs that depend on the VPN from within the bash script the script essentially pauses until the program finishes or exits. This keeps me from being able to test whether the VPN is active or not.
I thought that maybe I could just make them separate processes and activate them manually once I was connected to the VPN. In this way I could run a script to check the connection status of the VPN and somehow trigger the programs to stop once the connection was lost but this raised a secondary problem.
2nd Problem and questions:
Once the VPN connection is lost, how can I tell a program to quit or exit nicely without killing it, and even if I have to kill it in order to stop it, how would I do that without being present since killing a program requires input from the user in the form of the super user password?
Here is an example of the code I've been attempting so far. It functions in its current state with myprogram01 commented out, but it doesn't solve the problems I've mentioned above.
Any advice?Code:#!/bin/bash # The following might work as a conditional for programs that depend on the VPN in order to run or for programs that might need to stop running if the VPN is inactive. nmcli -p con up uuid #insert_connection_id #Attempt a connection to the VPN vpnstring="" vpnstring=`nmcli -t -f VPN con status |grep yes` if [ "$vpnstring" = "yes" ]; then echo VPN connection is active #dependency can be run here. sleep = 5 # myprogram01 #this line stops the bash script from continuing. Consider maybe using a "watch" command??? else echo VPN connection is inactive #Possibly retry the connection in the loop below if not connected. fi #echo The contents of the vpn string are as follows. #echo $vpnstring while : do vpnstring=`nmcli -t -f VPN con status |grep yes` #Executed as long as condition is true and/or, up to a disaster-condition if any. if [ "$vpnstring" = "yes" ]; then echo VPN connection is still active else echo VPN not connected. #Possibly retry the VPN connection here. break fi done