Auto Configure Proxy in Ubuntu


It is painful to turn the proxy on and off in my Ubuntu laptop between office and home.  As a lazy guy, I would like to make it automatic. Easy life now 🙂
1) Create 3 scripts named proxy_on, proxy_off and check_proxy under /usr/local/bin.
#!/bin/bash
#proxy_on
gsettings set org.gnome.system.proxy.socks host ‘proxy.company.local’
gsettings set org.gnome.system.proxy.socks port 80
gsettings set org.gnome.system.proxy mode ‘manual’
#!/bin/bash
#proxy_off
gsettings set org.gnome.system.proxy mode ‘none’

#!/bin/bash
#check_proxy
ping_test=`ping -c 2 proxy.company.local | grep bytes | wc -l`
if [ “$ping_test” -gt 1 ]; then
proxy_on
else
proxy_off
fi

2) Add check_proxy to the auto startup programes by creating the file ~/.config/autostart/check_proxy.desktop
[Desktop Entry]
Type=Application
Exec=check_proxy
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_AU]=check_proxy
Name=check_proxy
download_icon
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s