Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a script that sets my proxy automatically depending upon the connection and so its placed in /etc/network/if-up.d/ folder. I set the proxy using gsettings tool and then I want to show a notification on the desktop.

I use notify OSD as follows:

notify-send -u 'critical' -i /home/vivek/Downloads/proxy.ico 'SetProxy Status' 'proxy set to auto'

The script runs fine because i tried to print some log messages into a file which suggest that the script is being run, But i do not see any visible changes when i check my proxy settings, System Settings->Network Proxy, I see that the proxy is unchanged although it has changed actually[I checked the browser and the proxy settings were applied], Also I see no notification.

Amazingly if i run the script explicitly as follows:

cd /etc/network/if-up.d/
sudo ./setproxy

I see the notification at once and also the changes are reflected in Network Proxy settings. Why does this happen? How can I fix this? I am on a ubuntu 12.04 system.

share|improve this question
including export DISPLAY=:0 at the beginning of the script might help you with making the notifications visible –  Glutanimate Dec 30 '12 at 21:56
Thanks @MHC , i solved the problem with notifications by adding these two things to the bash script: **DISPLAY=:0 && export XAUTHORITY=/home/vivek/.Xauthority ** considering that the bash script showed errors about X11 authorizations when i dumped them into a file. –  Vivek Pradhan Jan 2 '13 at 17:09
add comment

2 Answers

Anything not in your home folder needs root permission to execute for sake of security in case of multi-user systems. Place the proxy settings script in the home folder inside a special folder, say ~/commands. Add this line PATH=$PATH:~/commands in .bashrc

echo 'PATH=$PATH:~/commands' >> .bashrc

Now, every time you run setproxy like any other command, like ls or date, proxy will be set. Just add sudo inside the script to avoid permission clashing.

Alternatively 1 :

This forum explains about Upstart which is quite simple to use.

Alternatively 2 :

Just enable root account on your system and always use that.
Warning : This is dangerous for the system in case you are not familiar with the system functioning, you tend to make silly or sloppy mistakes or for some reason are distracted and unknowingly make a mistake.

share|improve this answer
thanks for your reply. Now the script is running as I mentioned and i changed the ownership to root. The main reason for me to put that script in /etc/network/if-up.d is because I want that script to run when my laptop is connected to a network on an if up kind of an event. So thats a constraint. I do not want to run it on startup or like other command. The network manager automatically runs the scripts in the if-up.d folder on an active connection. –  Vivek Pradhan Dec 30 '12 at 14:21
your alternative 2 is a terrible idea - always logging in as root means that a single typo or wrong click can completely destroy your computer's OS. –  ImaginaryRobots Jan 27 '13 at 16:40
@ImaginaryRobots Then follow alternative 1. Last one is, as you say, hazardous. I only included it to cover all things I could think of. –  VedVals Jan 27 '13 at 16:45
add comment

I would suggest just adding the script to /etc/bash_completion which should get used every time you open a terminal as it is contained at the end of ~/.bashrc. Alternatively you can add the script to the end of ~.bashrc directly. If you choose to add it to bash_completion it should contain the line

. /etc/network/if-up.d/setproxy

and you should check ~./bashrc to make sure that bash_completion is used (it is at the end of the file). The end of my ~./bashrc looks like

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion

Just so you can make sure bash_completion is not commented out.

share|improve this answer
As to your question of WHY it happens I do not know :( –  fred.smalley Dec 30 '12 at 8:36
Thanks @fred.smiley but i need that script to run when an active connection is established only. Thats precisely why i placed it in the /etc/network/if-up.d –  Vivek Pradhan Dec 30 '12 at 14:22
You can also try make an alias, named say setmyproxy, so that whwn you need to set your proxy you can simply type setmyproxy into your terminal and your script is run. I know this is not automatic but it sure is easier than what you currently say works. To do this all you have to do is make a file as root named ~/.bash_aliases and in it have alias setmyproxy='. /etc/network/if-up.d/setproxy' –  fred.smalley Dec 31 '12 at 1:32
bash_completion is not a good place to put network setup scripts - that file should only contain things related to tab-completion. –  ImaginaryRobots Jan 27 '13 at 16:38
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.