最近测试文件拷贝中是否会出错,简单写了个脚本,并已经在实践中得到应用,现记录下,方便以后使用或查找;
1、测试文件拷贝
1 #!/bin/bash
2
3 clear
4 i=1
5 file1=testfile
6 file2=/media/dxh
7 file3=/media/dxh/testfile #设定拷贝的目录
8 if [ ! -df $file1 ]; #检测要拷贝的文件是否存在
9 then
10 echo "**********the copy dir will be from $file1 to $file2************** " 》log.txt
11 fi
12
13 while [ $i -lt 5 ] #设置拷贝的测试
14 do
15 echo "************copy $i times*************"
16 cp -rv $file1 $file2 #拷贝文件到目录地址
17 sync
18
19 echo "*************test diff $i times**************"
20 diff -rsv $file1 $file3 #比较拷贝的文件是否相同,-r 递归检测子文件,-sv 显示过程
21 if [ $? -ne 0 ]; #判断上一条命令是否执行成功
22 then
23 echo "%%%%%%%%%%%%diff error $i %%%%%%%%%%%%%%%" >> error
24 else
25 echo "************diff $i ok ****************" >> ok
26 fi
27
28 sleep 1
29 rm -rfv $file3 #删除文件,方便下次拷贝到该目录
30 i=`expr $i + 1`
31 done
2、应用程序打开关闭测试
以下程序主要检测某些应用软件是否能正常开启,开启一定时间后关闭;
1 #!/bin/bash
2
3 clear
4
5 read -p "please input the repeat num:" num
6 i=0
7 while [ $i -lt $num ] #确定要测试的循环次数
8 do
9 /usr/bin/gnome-mplayer & sleep 20;eval 'kill -9 $!'&>/dev/null #开启应用程序,保持20秒,然后杀掉该程序的进程;
将stdout和stderr都重定向到/dev/null
10 sleep 20
11 /usr/bin/gnome-about & sleep 20;eval 'kill -9 $!'&>/dev/null
12 sleep 20
13 /usr/bin/gnome-about-me & sleep 20;eval 'kill -9 $!'&>/dev/null
14 sleep 20
15 /usr/bin/gnome-power-preferences & sleep 20;eval 'kill -9 $!'&>/dev/null
16 sleep 20
17 /usr/bin/gnome-network-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
18 sleep 20
19 /usr/bin/gnome-appearance-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
20 sleep 20
21 /usr/bin/gnome-at-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
22 sleep 20
23 /usr/bin/gnome-audio-profiles-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
24 sleep 20
25 /usr/bin/gnome-calculator & sleep 20;eval 'kill -9 $!'&>/dev/null
26 sleep 20
27 /usr/bin/gnome-character-map & sleep 20;eval 'kill -9 $!'&>/dev/null
28 sleep 20
29 /usr/bin/gnome-control-center & sleep 20;eval 'kill -9 $!'&>/dev/null
30 sleep 20
31 /usr/bin/gnome-session-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
32 sleep 20
33 /usr/bin/gnome-sound-recorder & sleep 20;eval 'kill -9 $!'&>/dev/null
34 sleep 20
35 /usr/bin/gnome-sudoku & sleep 20;eval 'kill -9 $!'&>/dev/null
36 sleep 20
37 /usr/bin/gnome-system-monitor & sleep 20;eval 'kill -9 $!'&>/dev/null
38 sleep 20
39 /usr/bin/gnome-file-share-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
40 sleep 20
41 /usr/bin/gnome-help & sleep 20;eval 'kill -9 $!'&>/dev/null
42 sleep 20
43 /usr/bin/gnome-keyboard-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
44 sleep 20
45 /usr/bin/gnome-volume-control & sleep 20;eval 'kill -9 $!'&>/dev/null
46 sleep 20
47 /usr/bin/gnome-mouse-properties & sleep 20;eval 'kill -9 $!'&>/dev/null
48 sleep 20
49 /usr/bin/cheese & sleep 20;eval 'kill -9 $!'&>/dev/null
50 sleep 20
51 /usr/bin/chmsee & sleep 20;eval 'kill -9 $!'&>/dev/null
52 sleep 20
53 /usr/bin/firefox & sleep 20;eval 'kill -9 $!'&>/dev/null
54 sleep 20
55 /usr/bin/gwget & sleep 20;eval 'kill -9 $!'&>/dev/null
56 sleep 20
57 /usr/bin/audacious & sleep 20;eval 'kill -9 $!'&>/dev/null
58 sleep 20
59 /usr/bin/brasero & sleep 20;eval 'kill -9 $!'&>/dev/null
60 sleep 20
61 /usr/bin/gnome-open gsp/ok-gsp & sleep 20;eval 'kill -9 $!'&>/dev/null
62 sleep 20
63 /usr/bin/eclipse & sleep 80;eval 'kill -9 $!'&>/dev/null
64 sleep 20
65 /usr/bin/thunderbird & sleep 20;eval 'kill -9 $!'&>/dev/null
66 sleep 20
67 /usr/bin/gnome-text-editor & sleep 20;eval 'kill -9 $!'&>/dev/null
68 sleep 20
69
70 i=`expr $i + 1` 判断测试次数
71
72
73 function Killapply() 检查少数应用程序未被杀死的进程,并取出该PID ,后杀掉;
74 {
75 ps au |grep $a1 >tmp.txt
76 for line in 1;
77 do
78 b1=`head -n 1 tmp.txt |tail -1|cut -c 10-14` 取PID
79 kill -9 $b1
80 done
81 }
82
83 a1=thunderbird 依次检查对应的程序,并杀掉;
84 Killapply
85 a1=eclipse
86 Killapply
87 a1=editor
88 Killapply
89 a1=ok-gsp
90 Killapply
91 #a1=thunderbird
92 #Killapply
93
94 done
95
96 echo "**************test apply is over********************"
本文来自博客园,作者:{Julius},转载请注明原文链接:https://www.cnblogs.com/bestechshare/p/16447841.html
可微信加我,了解更多,WeChat:{KingisOK}