I set the following line in cron job under /etc/cron.d/find_old_file
* * * * * root [[ -d /var/log/ambari-metrics-collector ]] && find /var/log/ambari-metrics-collector -type f -mtime +10 -regex '.*\.log.*[0-9]$' -printf '%TY %Tb %Td %TH:%TM %P\n' >> /var/log/find_old_file this cron should find the logs that older then 10 day ( but only if /var/log/ambari-metrics-collector folder exists )
from some unclear reason we notice that /var/log/find_old_file not created
and when we test it this line works fine on shell bash but not from cron
we also add 2>&1 in the end of the file but this not work
please advice what is wrong in my cron job ?
more /etc/cron.d/find_old_file * * * * * root [[ -d /var/log/ambari-metrics-collector ]] && find /var/log/ambari-metrics-collector -type f -mtime +10 -regex '.*\.log.*[0-9]$' -printf '%TY %Tb %Td %TH:%TM %P\n' >> /var/log/find_old_file 2>&1 example when we test it on shell bash
[[ -d /var/log/ambari-metrics-collector ]] && find /var/log/ambari-metrics-collector -type f -mtime +10 -regex '.*\.log.*[0-9]$' -printf '%TY %Tb %Td %TH:%TM %P\n' 2018 Aug 13 12:54 collector-gc.log-201808130951 2018 Aug 13 04:22 collector-gc.log-201808130403 2018 Aug 01 12:40 gc.log-201808011229 2018 Aug 01 12:40 collector-gc.log-201808011229 2018 Aug 09 15:36 gc.log-201808091332 2018 Aug 09 10:50 gc.log-201808090825 2018 Aug 13 04:02 collector-gc.log-201808130346 2018 Aug 13 16:51 gc.log-201808131358 2018 Aug 01 13:35 gc.log-201808011241 2018 Aug 01 13:35 collector-gc.log-201808011241 2018 Aug 09 15:39 collector-gc.log-201808091332 2018 Aug 02 23:06 gc.log-201808022256 when I put this
* * * * * root echo test >> /var/log/test then its works , but not my line as described
so what are happens here?
findcommand ends shortly after the-printf.