【问题标题】:Error with Unix shell script Find and delete based on hoursUnix shell脚本错误根据小时查找和删除
【发布时间】:2017-08-07 15:45:21
【问题描述】:

我正在尝试根据在 shell 脚本中使用以下语句创建的日期删除 unix 中的文件夹内容。

find /mypath -mmin +$((60*24*1)) -exec rm -rf {} \;

我已配置为从 Control M 运行此脚本。这会删除文件夹,但脚本以错误代码 1 结尾。如何避免出现错误,以免我的工作失败?

find: '/mypath/Xdb/20170802_001028': No such file or directory find: '/mypath/Xdb/20170802_001027': No such file or directory find: '/mypath/Xdb/20170801_142539': No such file or directory

【问题讨论】:

    标签: shell unix delete-file control-m


    【解决方案1】:

    我不明白你为什么要使用

    min +$((60*24*1))   
    

    使用这个:

    find /mypath -mtime +1 -exec rm -rf {} \;    
    

    或者这个删除的目录没有检查它是否为空

    find /mypath -mtime +7 -type d -print0 | xargs -0 rm -rf    
    

    +7 删除旧的 then ,-7 删除从今天到 7

    【讨论】:

      【解决方案2】:

      除了 SamOl 的回答之外,如果你想坚持原来的命令,那么你可以告诉 Control-M 接受字符串 No such file or directory 作为“OK”。

      为此,只需在作业的最后一个选项卡中添加一个 On/Do Action def =

      On Do Actions
      Specific statement output    
      Statement = *    
      Code = *No such file or directory*    
      Do = Set job to OK
      

      这里有一个 YouTube 剪辑 - https://www.youtube.com/watch?v=Y3S7GdAwjQ8

      【讨论】:

      • 感谢您的帮助!
      猜你喜欢
      • 2016-03-18
      • 2016-05-31
      • 2016-03-22
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多