crontab and find

I want to delete .txt files in specific folder, which I succeed from the command line:
Code:
/usr/bin/find /path/to/ -name "*.txt" -delete

However, the command does not work from cron, despite using absolute paths:
Code:
@daily /usr/bin/find /path/to/ -name "*.txt" -delete > /dev/null 2&>1

I tested also with -print instead of -delete, redirecting output to a file, but it does not work either and created file is empty:
Code:
@daily /usr/bin/find /path/to/ -name "*.txt" -print > /home/me/test.txt 2&>1

Any advices?
 
Looks ok:
Code:
Dec  5 12:00:00 tazar /usr/sbin/cron[81444]: (root) CMD (/usr/libexec/atrun)
Dec  5 12:00:00 tazar /usr/sbin/cron[81446]: (operator) CMD (/usr/libexec/save-entropy)
Dec  5 12:01:28 tazar crontab[81463]: (pacija) BEGIN EDIT (pacija)
Dec  5 12:01:57 tazar crontab[81463]: (pacija) REPLACE (pacija)
Dec  5 12:01:57 tazar crontab[81463]: (pacija) END EDIT (pacija)
Dec  5 12:02:00 tazar /usr/sbin/cron[969]: (pacija) RELOAD (tabs/pacija)
Dec  5 12:03:00 tazar /usr/sbin/cron[81499]: (pacija) CMD (/usr/bin/find /path/to/ -name "*.txt" -print > /home/me/test.txt 2&>1)
Dec  5 12:05:00 tazar /usr/sbin/cron[81562]: (root) CMD (/usr/libexec/atrun)

/home/me/test.txt is still empty.
 
Hmmm.... Not sure but the shell might try to glob(1) the asterisk. Try using single quotes instead of double quotes.
 
It'll not explain your problem, but try writing your command in a file (shell script), make it executable and run this file instead of directly the command.
 
I can't find anything inherently wrong with the command. There's no errors either. The only logical conclusion would be that /path/to/ doesn't contain any *.txt files.
 
Directory is definitely not empty, and it contains txt files. Command works fine from console.
 
Uh, now it worked. A typo as usual :(

As a side effect, I forgot to put -mtime +7 which I originally wanted and I lost all files instead of those older than 7 days.

Well... there is a proverb in Serbian which could be translated similar to "you pay for school one way or another" :)
 
Back
Top