专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

用cron工具加上脚本实现自动更换桌面

百度收藏 QQ搜藏

自己买了一个柯达7590数码相机,拍了一些照片,还有点专业水准,就拿来作桌面。这么多图片到底选那一个,放弃那一个呢?最后决定,都选,都用来左桌面,让系统每30分钟自动换一个。利用系统子带的工具cron. 再加上自己编写的脚本,很容易实现。下面给出从文件夹中随机取出一副图片的脚本程序:


#!/bin/bash

#trim the charactor in head and tail

L_trim()
 

/*该函数取掉变量rand_time左边所有的空格:*/

{
tmp=${rand_time:0:1}

while [ $tmp = 0 ]
do
rand_time=${rand_time:1}

tmp=${rand_time:0:1}
done
}

R_trim()
 

/*该函数取掉变量rand_time右边所有的空格:*/

{{
Len=${#rand_time}
let "sLen =Len -1"
tmp=${rand_time:sLen:1}
while [ $tmp = 0 ]
do
rand_time=${rand_time:0:$sLen}
Len=${#rand_time}
let "sLen =Len -1"
tmp=${rand_time:sLen:1}
done
}

#get current time as random
rand_time=`date '+%N'`
#trim the "0" from the var
#rand_time=${rand_time:0:6}
L_trim
R_trim
#get filecount of $1
fcount=`ls $1 | wc -l`
echo "fcount $fcount"
#get a random number between 1 and fcount
rand_num=$(($rand_time % $fcount ))
echo $rand_num

tmp=1
for file in $1/*.jpg
do
if [ $tmp -lt $rand_num ]
then
let "tmp=tmp+1"
continue
fi
}

/*可以将随机取出的图片设为桌面:*/


#qiv -Tx $HOME/.wallpaper.jpg
echo "file:$file"
break;
done

上一篇:为方便在Ubuntu下使用Drcom而编的SHELL 下一篇:Shell脚本(功能:备份压缩用户目录所有文件成.tar.gz格式并发送到邮箱)

power by soyo123 2007-2008