# crontab and find



## pacija (Dec 5, 2012)

I want to delete .txt files in specific folder, which I succeed from the command line:

```
/usr/bin/find /path/to/ -name "*.txt" -delete
```

However, the command does not work from cron, despite using absolute paths:

```
@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:

```
@daily /usr/bin/find /path/to/ -name "*.txt" -print > /home/me/test.txt 2&>1
```

Any advices?


----------



## SirDice (Dec 5, 2012)

Look for errors in /var/log/cron.


----------



## pacija (Dec 5, 2012)

Looks ok:

```
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.


----------



## SirDice (Dec 5, 2012)

Hmmm.... Not sure but the shell might try to glob(1) the asterisk. Try using single quotes instead of double quotes.


----------



## pacija (Dec 5, 2012)

Still nothing


----------



## mamalos (Dec 5, 2012)

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.


----------



## SirDice (Dec 5, 2012)

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.


----------



## pacija (Dec 5, 2012)

Directory is definitely not empty, and it contains txt files. Command works fine from console.


----------



## DutchDaemon (Dec 5, 2012)

```
2&>1
```
 should be 
	
	



```
2>&1
```


----------



## pacija (Dec 5, 2012)

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"


----------

