1

I checked many questions like my issue but could not find a solution yet

Following command works without any problem

rm -rf <PATH>/<pattern>*$(date +'%Y%m%d' -d "-2 days")*.csv

I have edited crontab with like following line

39 9  * * * rm -rf <PATH>/<pattern>*$(date +\'\%Y\%m\%d\' -d \"-2 days\")*.csv

But I got following error when crond runs my command

> date: extra operand `days"'
Try `date --help' for more information.

I could not find any solution yet, do you have any idea ?

I have tons of file to delete, rm works better than find (-exec rm) command.

3
  • 1
    Why did you escape the ' and "?
    – muru
    Dec 26, 2017 at 7:14
  • I tried many many recommendation and mixed version of recommendation.Now it works without escaping ' and " Thanks a lot Dec 26, 2017 at 8:04
  • Try date -d -2days (ommit the blank). This should work also without the quoting problem.
    – ridgy
    Dec 26, 2017 at 12:03

1 Answer 1

2

You don't need to escape quotes in crontab. Only % is special in most crontabs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .