Ubuntu 12.04自动切换桌面背景

Ubuntu 12.04自动切换桌面背景

Ubuntu12.04禁止U盘等设备的自动挂载方法如下:

Linux6下部署2个Tomcat7.0.40及注册成服务

 

在图形界面(字符界面无效)内进入系统终端,ctrl+alt+T或者gnome-terminal

 

以前在gnome2时使用gconftool可以改变ubuntu的桌面背景的,装了12.04后,发现不行了,研究了一下,原来改用gsettings这个工具了.

禁止自动挂载:
$ gsettings setorg.gnome.desktop.media-handling automount false

[[email protected]
conf]# cd /opt/

 

禁止自动挂载并打开:
$ gsettings setorg.gnome.desktop.media-handling automount-open false

[[email protected]
opt]# ll

我卸载了unity,装的是gnome-panel桌面.

允许自动挂载:
$ gsettings set org.gnome.desktop.media-handlingautomount true

total 16

 

允许自动挂载并打开:
$ gsettings setorg.gnome.desktop.media-handling automount-open true

drwxr-xr-x. 8  500  500 4096 Apr  4 19:52 jdk1.7.0_21

脚本如下:

drwxr-xr-x. 2 root root 4096 May 10  2012 rh

 

drwxr-xr-x. 9 root root 4096 May 31 00:23 TomcatA

[cpp] 

drwxr-xr-x. 9 root root 4096 May 31 00:26 TomcatB

#!/bin/bash  

[[email protected]
opt]# ls /etc/init.d/Tomcat*

confFile=”.switchbg.conf”  

/etc/init.d/TomcatA  /etc/init.d/TomcatB

cd $(dirname $0)  

[[email protected]
opt]# ls /tmp/

filepath=$PWD  

hsperfdata_root  tomcatA_process_count.txt
 tomcatB_process_count.txt  yum.log

find $filepath | grep -E “.jpg$|.png$|.JPG$|.PNG$” > $confFile  

[[email protected]
opt]# chkconfig –add TomcatA

cnt=`cat $confFile | wc -l`  

[[email protected]
opt]# chkconfig –add TomcatB

  

[[email protected]
opt]# chkconfig –list|grep Tomcat

while true  

TomcatA         0:off   1:off   2:on    3:on    4:on    5:on    6:off

do  

TomcatB         0:off   1:off   2:on    3:on    4:on    5:on    6:off

line=$(($RANDOM % $cnt + 1))  

 

bgfile=$(head -n $line $confFile | tail -n 1)  

 

bgfile=”‘file://$bgfile'”  

[[email protected]
bin]# more /etc/init.d/TomcatA

bkfile=$(gsettings get org.gnome.desktop.background picture-uri)  

#!/bin/bash

echo $bkfile  

#chkconfig: 2345 10 90

echo $bgfile  

#description:TomcatA service

if [ $bkfile != $bgfile ]  

JAVA_HOME=/opt/jdk1.7.0_21

then  

CATALINA_HOME=/opt/TomcatA

break  

TOMCAT_START=$CATALINA_HOME/bin/startup.sh

fi  

TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh

done  

 

gsettings set org.gnome.desktop.background picture-uri $bgfile  

# source function library.

rm -f $confFile  

. /etc/rc.d/init.d/functions

保存后加到crontab里发现脚本的gsettings set不起作用.所以只能改一下了:

# check that networking is up.

 

[ “${NETWORKING}” = “no” ] && exit 0

[cpp] 

# check for tomcat script

#!/bin/bash  

if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then

confFile=”.switchbg.conf”  

         echo “TomcatA not valilable…”

changedtime=600  

        exit

cd $(dirname $0)  

fi

filepath=$PWD  

start(){

find $filepath | grep -E “.jpg$|.png$|.JPG$|.PNG$” > $confFile  

        echo -n “Starting TomcatA: “

cnt=`cat $confFile | wc -l`  

        daemon $TOMCAT_START

while true  

        echo

do  

        touch /var/lock/subsys/tomcat

while true  

}

do  

stop(){

line=$(($RANDOM % $cnt + 1))  

                ps ax –width=1000 | grep “/opt/TomcatA/temp
[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ”
“}’ 

bgfile=$(head -n $line $confFile | tail -n 1)  

 | wc | awk ‘{print $2}’ > /tmp/tomcatA_process_count.txt

bgfile=”‘file://$bgfile'”  

        read line < /tmp/tomcatA_process_count.txt

bkfile=$(gsettings get org.gnome.desktop.background picture-uri)  

        if [ $line -gt 0 ]; then

if [ $bkfile != $bgfile ]  

                echo -n “TomcatA ( pid “

then  

                ps ax –width=1000 | grep “/opt/TomcatA/temp
org.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’

break  

                echo -n “) is running…”

fi  

                                echo

done  

 

gsettings set org.gnome.desktop.background picture-uri $bgfile >>
tmp.log  

                                echo -n $”Shutting down TomcatA: “

sleep $changedtime  

                                daemon $TOMCAT_STOP

done  

                                rm -f /var/lock/subsys/tomcat.pid echo

rm -f $confFile  

        else

让脚本在启动时自动加载就好了.间隔时间修改changedtime的值就行了,单位为秒.

                echo “TomcatA is stopped”

 

        fi

12.04自动切换桌面背景
以前在gnome2时使用gconftool可以改变ubuntu的桌面背景的,装了12.04后,发现不行了,研究了一下,原来改用gsettings这个工…

}

restart(){

        stop

        start

}

status(){

发表评论

电子邮件地址不会被公开。 必填项已用*标注