Discuz! Board

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

[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
复制代码



使用道具 举报

Rank: 3Rank: 3

发表于 2014-1-9 02:27:19 |显示全部楼层
好帖要顶,楼主的头像还是不错滴

使用道具 举报

Rank: 3Rank: 3

发表于 2014-3-6 10:18:44 |显示全部楼层
好帖要顶,楼主的头像还是不错滴

使用道具 举报

Rank: 2

发表于 2014-9-18 07:23:20 |显示全部楼层
骑士服务端天上碑SF服务端真封神服务端成吉思汗2服务端征服私服服务端
美丽世界服务端科洛斯Season3(第三季)完美升级版服务端石器时代服务端
网页游戏服务端亮剑服务端洪荒神话服务端弹弹堂服务端魔域烈焰S服务端
街头篮球服务端美丽世界Nage服务端支持狂战雷霆裁决战神新装备S真属性
传说45服务端丝路传说倚天2龙驹S服务端精灵复兴服务端大话西游2服务端
完美世界服S端九阴真经服务端凡人修真服务端天之炼狱服务端墨香服务端
奇迹mu官方多线攻城服务端魔兽世界服务端梦幻西游服端传奇外传S服务端
神迹ol最新S服务端仙境传说ro服务端蜀门一键服务端天之炼狱私服一条龙
新天骄2916服务端剑侠情缘SF服务端雄霸密传二转S服端十二之天贰服务端
墨香外传服务端冒险岛服务端绝对女神服务端跑跑卡丁车S服端龙ol服务端
新天上碑4305转盘龙服务端抗战服端A3服务端决战服务端石器时代服务端
神迹服务端RF服务端神将三国服务端仙境传说服务端天龙八部私服服务端
破天一剑服务端QQ西游私服服务端奇迹mu服务端传奇服务端A3-219服务端
永恒之塔杀星时代私服务端洛汗服务端新天骄服务端惊天动地私服S服务端
倚天2自由世界帝王私服务端天堂2服务端挑战服务端剑侠情缘怀旧S服务端
linux版WIN版csa完整S服务端天龙八部linux-win服务端剑侠世界私服务端
英雄远征S服务端传奇世界服务端飞飞SF服务端密传服务端新魔界私服务端
千年九妖服务端神武奇章私服侠众道原版极乐洞挑战S服务端骑士ebsf工具
完美世界国际经典服务端神泣S服端英雄王座travia服务端奇侠XIAH服务端
丝路传说SilkRoadOnlinev欧亚大陆S服务端魔力宝贝十转变态怀旧S服务端
蜀门服务端绿色征途服务端linux-win版圣者注册怀旧世外桃源私服服务端
卧龙吟问仙服务端劲舞团SF服务端醉西游服务端刀剑S服务端机战私服务端
英雄王座ol服务端飞马翅膀工会战国战韩国大陆版幻灵游侠服务端红月S端
征途服务端机战魔兵变服务端RF64位核战风暴台湾服务端魔力宝贝服务端
浪漫Q糖服务端劲舞团新服务端红月魔王S版服务端跑跑卡丁车私服服务端
冒险岛100%汉化服务端征服65AC私服服务端破天一剑变态虎鼠私服服务端
新魔界2.0win版新副本SF服务端天羽微变完美5转决战v10.8副本NEO服务端
天堂2最新ctSQL64位服务端梦幻西游2.0盛大服务端魔域中众神归来服务端
惊天动地变态极品三剑客服务魔兽世界台国服仿官方芒果服务端wowserver
天之炼狱6.65归来版铁血DK2鬼魅服务端传奇归来刺客强化私服服务端
真封神楼兰天尊地魔国际版服务端热血江湖255转武勋装备门派刺客服务端
网页传奇游戏S服务端回合传奇世界外传2服务端倚天2帝王烽火龙驹服务端
热血传奇神龙合击服务端仿盛大火龙精品玉兔元素皓月必杀炎龙新副本S服
魔域最新服务端灭世魔劫吸血鬼S服梦幻国度S服务端骑士linux-win服务端
传奇广告代理(详细介绍)http://www.e7if.com/index15.htm
IDC服务器以及空间租用—(详细介绍)http://www.e7if.com/
传奇开sf一条龙开区服务官方网站-http://www.e7if.com
天龙八部开私服一条龙服务-www.e7if.com
魔域私服开区一条龙服务-www.e7if.com-客服咨询QQ(企鹅扣扣)49333685
后浪科技www.e7if.com商业版本免费开放下载(只能单线程单个下载)
http://www.e7if.com/soft/index.html












天龙八部开私服一条龙服务 魔域私服开区一条龙服务

使用道具 举报

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

Archiver|IC Test Forum Inc.

GMT+8, 2019-3-20 21:04 , Processed in 0.834759 second(s), 12 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部