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 06-01-2014, 05:09 PM   #1
abourke
Member
 
Registered: Dec 2006
Posts: 108

Rep: Reputation: 17
Xscreensaver VPN Network Disconnect/Reconnect Script


Hi, having trouble with a script I made to disconnect/reconnect my network connection and vpn. Everything works except for the reconnection of my vpn using nmcli con up.

It behaves differently depending how it is invoked. If I use the terminal to start the script it works. But if I start the script as an /etc/xdg/autostart desktop entry it fails on reconnection of the vpn. And there is no output for me to determine what is wrong.

The command alone runs fine in the terminal. (nmcli con up blah blah) But fails as part of the script.
I guess it is either a permission problem or the preceding sleep statement doesnt work as intended.

Cany somone help me fix this? Im very close!

Code:
#!/bin/bash

process() {
while read input; do 
  case "$input" in
    UNBLANK*)	notifySendUp.sh && echo NET_UP && date && sudo dbus-send --system --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:false && sleep 10 && sudo -u aubrey nmcli con up uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7;;
    LOCK*)      nmcli con down uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7 && sleep 4 && notifySendDown.sh && echo NET_DOWN && date && sudo dbus-send --system --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:true ;;
  esac
done
}

/usr/bin/xscreensaver-command -watch | process

Last edited by abourke; 06-01-2014 at 05:10 PM.
 
Old 06-03-2014, 07:58 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Might have a problem with the "echo NET_DOWN" as an autostart doesn't have anywhere to send it...

nit: It would make it easier to read if those long lines were broken up. No need for the && syntax either - just put them on a new line with suitable indentation. It might also make it easier to debug.
 
Old 06-07-2014, 04:35 PM   #3
abourke
Member
 
Registered: Dec 2006
Posts: 108

Original Poster
Rep: Reputation: 17
Progress

Okay, I did this and now the nmcli commands work!

Code:
#!/bin/bash

process() {
while read input; do 
  case "$input" in
    UNBLANK*)	
                notifySendUp.sh 
		sudo dbus-send --system --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:false 
		sleep 5s
		nmcli con up uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7 
		;;
    LOCK*)     	 
                 notifySendDown.sh
		 nmcli con down uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7
		 sleep 4s
		 sudo dbus-send --system --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:true 
		;;
  esac
done
}

/usr/bin/xscreensaver-command -watch | process
And again it fully works when launched from the terminal.
However, if I autostart it by adding this line to the end of my .bash_profile, it all works except for the dbus commands
Code:
/usr/local/bin/lockedNet.sh &
I also have the following in my sudeors:
Code:
aubrey ALL= NOPASSWD: /usr/bin/dbus-send
root ALL= NOPASSWD: /usr/bin/dbus-send
aubrey ALL= NOPASSWD: /usr/bin/nmcli
root ALL= NOPASSWD: /usr/bin/nmcli
aubrey ALL= NOPASSWD: /usr/local/bin/lockedNet.sh
root ALL= NOPASSWD: /usr/local/bin/lockedNet.sh
What am I doing wrong here? Appreciate any help.
Regards
Aubrey.
 
Old 06-07-2014, 05:05 PM   #4
abourke
Member
 
Registered: Dec 2006
Posts: 108

Original Poster
Rep: Reputation: 17
more progress...

HI,

I tried using another command instead of the dbus commands
Code:
#!/bin/bash

process() {
while read input; do
  case "$input" in
    UNBLANK*)    notifySendUp.sh
                 #sudo dbus-send --system --dest=org.freedesktop.NetworkManager$
                 sudo ifconfig p32p1 up
                 sleep 5s
                 nmcli con up uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7        $
                 ;;
     LOCK*)	 notifySendDown.sh
                 nmcli con down uuid 5d7a4c02-2934-44e9-8f58-5d5010ec36c7
                 sleep 4s
                 #sudo dbus-send --system --dest=org.freedesktop.NetworkManager$
                 sudo ifconfig p32p1 down
                 ;;
  esac
done
Here I'm using sudo ifconfig interface up/down

Again it doesnt work from autostart (.bash_profile or gnome-session-properties) but it does from the terminal!!

I guess I am close here if anyone knows??
Regards
Aubrey.
 
Old 06-08-2014, 03:29 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
sudo requires a terminal for a password check... There is no terminal from autostart.
 
Old 06-08-2014, 09:56 AM   #6
abourke
Member
 
Registered: Dec 2006
Posts: 108

Original Poster
Rep: Reputation: 17
Solved

Yes, thats it. I had to use
Code:
!requiretty
in my sudeors file.
So Im thrilled now my desktop is a clam-shell now! It locks up the network when idle. Thanks!
:-)

Regards
Aubrey.
 
  


Reply

Tags
xscreensaver


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
disconnect and reconnect wireless after ubuntu 11 update. taste Linux - Newbie 2 08-29-2011 08:22 AM
No network packets sent immediately after quick physical disconnect and reconnect miracles Linux - Newbie 10 03-10-2011 12:48 AM
How do i make linux-ppp reconnect on disconnect? (pptp) Timtastic Linux - Networking 1 11-29-2010 03:32 PM
vpn connect/disconnect shell script rashmeepawar Programming 11 10-05-2009 09:15 AM
Script to reconnect the wired network automatically tinymark Linux - Networking 2 05-06-2009 05:50 AM

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

All times are GMT -5. The time now is 08:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration