Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 45996|回复: 4

[Shell] Unix Cshell检查文件最后修改时间并转移 [复制链接]

Rank: 8Rank: 8

发表于 2012-9-14 18:02:32 |显示全部楼层
本帖最后由 arthur 于 2012-9-14 18:05 编辑

给大家一个例子,用来cshell检查文件的最后修改时间,看是不是很久之前修改的,如果超过30天就转移去子目录

  1. #!/bin/csh
  2. # Script Name: AD6548 correcion factor check script
  3. # Function : script created for ad6548 correction facotr check
  4. # and remove offset files which older than 2 months
  5. # Rev0 - First release
  6. # By:
  7. # Rev1 - Add pop up window for no correction factor remind
  8. # By:
  9. ###################################################################
  10. # this scripts need to be released to /home3/msl/.ad6548_silveroff/
  11. ###################################################################
  12. set expire_days = 30 ##########days to expire correction factor

  13. set home_dir = "/home3/msl/.ad6548_silveroff/"
  14. set log_file = $home_dir"ad6548_offset_file_check.log"
  15. set temp_file = $home_dir"cf_check.temp"
  16. set host_id = `hostname`
  17. set tester_id = `echo $host_id|cut -c 1-8`
  18. set tester_id = "$tester_id""t"
  19. set home_dir = $home_dir$tester_id"/"
  20. set backup_dir = $home_dir"backup/"
  21. set today = `date '+%d-%m-%Y'`
  22. set tstamp = `date '+_%m_%d'`
  23. set toweek = `date '+%w'`
  24. set tonow = `date '+%H'`
  25. set exp_cnt = 0
  26. if (-d $home_dir) then
  27. ### check offset file dir ###
  28. if (! -d $backup_dir) then
  29. mkdir $backup_dir
  30. chmod 777 $backup_dir
  31. endif

  32. ### Monday to Friday day shift ###
  33. if ( $toweek > 0 && $toweek < 6 && $tonow > 8 && $tonow < 18 ) then
  34. ### start to check offset file ###
  35. echo "" > $temp_file
  36. find $home_dir -mtime +$expire_days -name '*silver_offset*' -exec ls {} >> $temp_file \;
  37. ### check every offset file in dir ###
  38. foreach record(`sed -n '/silver_offset/p' $temp_file`)
  39. set cf_file = $record
  40. set cf_noback = `echo $record|sed 's/backup//g'` #delete backup in full file name
  41. if ( $cf_file == $cf_noback ) then #current file is valid file, not in backup folder
  42. set exp_cnt = `expr $exp_cnt + 1`
  43. set cf_name = `echo $cf_file|sed 's/^\/[a-z0-9\/\.\_\-]*\///g'` # get file name without path
  44. echo `ls -l $cf_file|nawk -F " " '{print $6"-"$7"-"$8" "$9}'`" -- deleted at $today" >> $log_file

  45. cp -p $cf_file $backup_dir$cf_name"_at"$tstamp
  46. rm $cf_file

  47. echo "" >> $log_file
  48. endif
  49. end
  50. ### print how many offset files expired ###
  51. if ( $exp_cnt > 0) then
  52. echo "+---------------------------------------------------------------+"
  53. echo "| "$exp_cnt" correction factor files expired and deleted (exp "$expire_days" days) |"
  54. echo "| need to re-generate if program can not read correction factor |"
  55. echo "+---------------------------------------------------------------+"
  56. endif
  57. #**************************************************************************
  58. ### check is there any offset file still avaliable
  59. #**************************************************************************
  60. echo "" > $temp_file
  61. set exp_cnt = 0
  62. find $home_dir -name '*silver_offset*' -exec ls {} >> $temp_file \;
  63. ### check every offset file in dir ###
  64. foreach record(`sed -n '/silver_offset/p' $temp_file`)
  65. set cf_file = $record
  66. set cf_noback = `echo $record|sed 's/backup//g'` #delete backup in full file name
  67. if ( $cf_file == $cf_noback ) then #current file is valid file, not in backup folder
  68. set exp_cnt = `expr $exp_cnt + 1`
  69. endif
  70. end
  71. if ( $exp_cnt == 0) then
  72. echo "+--------------------------------------------------------------------+"
  73. echo "+ No creation factor is avaliable, please infrom LSG/PE to generate. +"
  74. echo "+--------------------------------------------------------------------+"
  75. #### popup x-window for alert
  76. if ( -f "/home3/msl/.ad6548_silveroff/No_CF_Error" ) then
  77. setenv LD_LIBRARY_PATH /image/bin.rls/custom/qa_custom/scripts/scan_startlot_endlot/STATS/ESUMMARY/lib
  78. /home3/msl/.ad6548_silveroff/No_CF_Error &
  79. setenv LD_LIBRARY_PATH /image/bin.rls/lib
  80. else
  81. echo "Warning\! No correction factor alert window missing\! PLEASE CALL PE\!"
  82. endif
  83. #### delete prod program and load correction factor program ##
  84. delete
  85. echo "+----------------------------------------------------------------------------------+"
  86. echo "Production program deleted, please call LSG/PE to run correction factor immediately\!"
  87. echo "+----------------------------------------------------------------------------------+"
  88. sleep 1;
  89. load "/home3/msl/.ad6548_silveroff/F_AD6548_2p2_TTR_DS_CAT_v0802_036_gen_subsilver_1/pd_ad6548_70d11_v0802_offset.load"
  90. echo "+-----------------------------------------------------------+"
  91. echo "+ PD pgm deleted, please call LSG/PE to run CF immediately\! +"
  92. echo "+ Correction factor program auto loaded, no need to reload\! +"
  93. echo "+-----------------------------------------------------------+"
  94. banner "CF pgm loaded"
  95. endif
  96. ### end of offset files checking ###
  97. endif
  98. else
  99. echo "###############################################"
  100. echo "#Current tester has no Correction factor files#"
  101. echo "###############################################"
  102. exit 0
  103. endif
  104. echo "+--------------------------------------------+"
  105. echo "| Correction factor files checking completed |"
  106. echo "+--------------------------------------------+"
  107. exit 0
复制代码



使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|IC Test Forum Inc.

GMT+8, 2023-3-31 11:56 , Processed in 0.291584 second(s), 11 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部