0

I'm trying to delete a folder contents in unix based on the date created using the following statement in a shell script.

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

I have configured to run this script from Control M. This deletes the folder however the script ends with the error code 1. How can i avoid getting the error so that my job does not get failed?

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

Srivatsan
  • 81
  • 1
  • 9

2 Answers2

2

I don't understand why do you use

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

use this:

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

or this removed directory without checking it is empty or not

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

+7 remove older then , -7 removes from today to 7

SamOl
  • 82
  • 1
  • 1
  • 10
1

In addition to the answer from SamOl, if you want to stick with your original command then you can tell the Control-M to accept the string No such file or directory as "OK".

To do this simply add an On/Do Action in the last tab of the job def =

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

There is a YouTube clip here - https://www.youtube.com/watch?v=Y3S7GdAwjQ8

Mark
  • 316
  • 1
  • 5