简体   繁体   中英

GNOME proxy switch in Ubuntu

I use Ubuntu and i'm new in shell scripting. I try to write shell script which will switch proxy mode in Ubuntu GNOME. For each switch i can write such scripts and to run it with launcher. This command switches proxy to none.

gconftool-2 -s -t string /system/proxy/mode none

And this one swithces proxy mode to manual, which i use at work:

gconftool-2 -s -t string /system/proxy/mode manual

Both ones works, but i want them to work together, with if-else. I want it to check current proxy mode and if current proxy mode is NONE, let it turn to MANUAL, and else if current proxy mode is MANUAL, let it to turn to NONE. I would be able to build this code, if i knew how to get current proxy mode name for using in script.

proxy_status=`gconftool-2 -g /system/proxy/mode`

if [ "$proxy_status" = "none" ]; then
    change_to="manual"
elif [ "$proxy_status" = "manual" ]; then
    change_to="none"
fi

gconftool-2 -s -t string /system/proxy/mode "$change_to"

You only need to use the -g switch to get the current status:

proxy_status=`gconftool-2 -g /system/proxy/mode`

if [ "$proxy_status" = "none" ]; then
    # proxy is off
    # do something clever
else
    # proxy is on
    # do something clever
fi

With this bash snippet you should be able to do whatever you want with :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM