Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I thought of using watch command to delete files in a directory every N seconds with the command running in background.

This is what I was planning to use:

nohup watch -n1200 rm -rf /var/log/radius/radacct/8.44.25.17/detail-2013* &

It works, but when I see the running process, it shows me the following output -

[root@Free-Radius 8.44.25.17]# ps -aef | grep watch
root     27326 10649  0 15:23 pts/0    00:00:00 watch -n1200 rm -rf /var/log/radius/radacct/8.44.25.17/detail-20130816
root     27404 10649  0 15:24 pts/0    00:00:00 grep watch

Now there will be a new file detail-20130817 tomorrow, which will not get deleted. Is there a way to achieve it using watch command. I know its easily doable using a simple bash script or cron job, but just wanted to know if it can be done using watch.

share|improve this question
1  
use rather .../detail-$(date +%Y%m%d) –  val0x00ff Aug 16 '13 at 10:27
1  
Or configure the application to not write any logs, if you're just going to delete them anyway. –  Michael Kjörling Aug 16 '13 at 10:45
1  
You should use watch 'rm -rf something*' to avoid the expansion of * by the shell before the execution of watch. –  enzotib Aug 16 '13 at 10:52
    
Thank you @val0x00ff. The suggestion worked –  Shrijit Aug 18 '13 at 18:50
    
Thank you @enzotib. Your suggestion too worked :) –  Shrijit Aug 18 '13 at 18:50
add comment

1 Answer

up vote 2 down vote accepted

If using the watch command from procps (which starts a shell to interpret the command line that's made out of the concatenation of its arguments), use:

nohup watch -n1200 'rm -rf /var/log/radius/radacct/8.44.25.17/detail-2013*' &

With some other implementations, you may have to call the shell manually:

nohup watch -n1200 sh -c 'rm -rf /var/log/radius/radacct/8.44.25.17/detail-2013*' &

Why not use cron though?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.