I am running this command every hour for cleaning up files:
# crontab -l
MAILTO=notify@localhost
0 */1 * * * find /var/www/tmp/ -name "*" -mmin +60 | /usr/bin/xargs /bin/rm -f -R
But every time the cronjob is executed an email with this error message is sent to my mail account:
/bin/rm: invalid option -- '^M'
Manually executing the command works fine:
find /var/www/tmp/ -name "*" -mmin +60 | /usr/bin/xargs /bin/rm -f -R
# ok
The logs show:
grep CRON /var/log/syslog
Dec 23 06:34:01 Ubuntu-1804-bionic-64-minimal CRON[29314]: (root) CMD (find /var/www/tmp/ -name "*" -mmin +60 | /usr/bin/xargs /bin/rm -f -R --^M)
So apparently the problem is in the cron file.
Regards,
^M
that's a carriage return. When you wrote that cron job, were you using any Windows-specific utilities ? See unix.stackexchange.com/questions/32001/…-exec
and-delete
options onfind
or the-print0
option to output items delimited with the null character.-name "*"
does nothing and can be left out.