2011-09-20 55 views
1

我使用Ubuntu,并且我是shell脚本中的新成员。我尝试编写将在Ubuntu GNOME中切换代理模式的shell脚本。 对于每个开关,我可以编写这样的脚本并使用启动器运行它。该命令将代理切换为无。Ubuntu中的GNOME代理交换机

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

而这一次swithces代理方式为手动,这是我在工作中使用:

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

两个那些作品,但我希望他们能一起工作,用的if-else。我想要它检查当前的代理模式,如果当前的代理模式是NONE,让它转向MANUAL,否则如果当前的代理模式是MANUAL,则让它变为NONE。如果我知道如何在脚本中使用当前代理模式名称,我将能够构建此代码。

回答

2

你只需要使用-g开关来获得当前状态:

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 

有了这个庆典段,您应该可以做任何你想要的:)

2
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"