Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1066167
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: Python/Ruby

2011-01-28 14:13:00

变态的需求:
 
  500*500的hash目录下有若干个文件,每次取10个文件模拟拷贝,计算出读的效率监控之。注意文件目录存在断层,比如可能/009/010根本不存在,要判断先。
 
  1. #!/bin/sh

 

  1. # author :expert1


  2. #DATE:2011-01-28


  3. # Usage: randomly get 10 files from 500*500 (000-499)hash directories,and copy them to tmp directory.


  4. # thus calculate the time it consumes.


  5. # NOTE:The 500 directories may not successive, in which case it has a breakpoint. e.g 000-100 120-499



  6. ############ define threshold #####



  7. threshold=5 # suppose 5Mb/s



  8. ########### full path #####


  9. fullpath=/tmp

  10. destdir=/dev/null


  11. touch num_10_$$ size.$$ time.$$


  12. #### randomly get 10 numbers ###



  13.  while [ `awk 'END{print NR}' $fullpath/num_10_$$ ` -lt 10 ];

  14.    do

  15.       tmp="${fullpath}/$((RANDOM%15))/$((RANDOM%15))"

  16.      #tmp="$fullpath/$(printf "%03d/%03d" $((RANDOM%500)) $((RANDOM%500)))"

  17.     
  18.       [ -d $tmp ] && echo $tmp >>num_10_$$

  19.    done


  20. ##### get time and size ;redirect to tmpfile #################


  21.    
  22.  for i in `cat $fullpath/num_10_$$` ;do

  23.      for j in `find $i -type f |head -1`;do

  24.        ls -l $j >>size.$$
  25.        #注意time是bash的reserved word/metadata, 而且它的默认输出到std err,要redirect必须{;}这种方式()注意里面的;分号,或者subshell
  26.        { time -p cp $j $destdir ;} >>$fullpath/time.$$ 2>&1

  27.      done

  28.  done
  29.   
  30. #### calculate the time and size of the test files ##############



  31.  sum_time=$(awk '/real/{s+=$2}END{print s}' $fullpath/time.$$) # seconds

  32.   
  33.  size=$(awk '{s+=$5}END{print s/1024/1024}' $fullpath/size.$$) # Mb



  34.  wrps=` awk 'BEGIN{print '$size'/'$sum_time' }'`


  35.  rm -f num_10_$$ size.$$ time.$$

  36. ###### check low or high ####



  37. if [ `echo "$wrps > $threshold" | bc` = 1 ]

  38.    then echo " warnings,please check your disk immediately!!!!"

  39.     exit 1

  40.   else echo "hi,guy,it seems fine ,don't worry ^_^ "

  41.   exit 0

  42. fi

阅读(1294) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~