Friday, August 2, 2013

Crontab

Creating a crontab is useful when you need to repeatedly execute a command.  Here's an example.  I want to find all files beginning with the string 'core' followed by any additional characters in the /storage/core directory.  If any are found, I want to delete only those older than two day.

Here's the command I want to execute-
$ find /storage/core/core* -type f -mtime -2 -exec /bin/rm {} \;

Now I'll put into a crontab-
$ crontab -e
# m h  dom mon dow   command
#
25      9       *       *       *       /usr/bin/find /storage/core/core* -type f -mtime -2 -exec /bin/rm {} \;



This crontab will execute at 9:25 am everyday in the month, every month, and everyday.


If you want to learn more about crontabs then browse the web.  This site is a very useful one.

http://linux.about.com/od/commands/l/blcmdl5_crontab.htm


No comments: