Knowledgebase

Portal Home > Knowledgebase > Articles Database > Cron to delete files


Cron to delete files




Posted by biggerboy, 06-15-2008, 08:45 PM
I want to setup a crontab to delete a file every 24 hours, I am not the best in crontab so was wondering if one of you could please give me the command I should use? Thanks, Alex

Posted by RN-Chris, 06-15-2008, 08:47 PM
Well one way you could do it is make a shell script that would delete the file, and then setup that shell script in your cron tab.

Posted by biggerboy, 06-15-2008, 08:50 PM
Alright that would work, what should I put into the script?

Posted by osphere, 06-15-2008, 09:01 PM
rm /path/to/file.ext

Posted by biggerboy, 06-15-2008, 09:08 PM
I should have known it would be that simple

Posted by insanelymacintosh, 06-15-2008, 09:12 PM
the shell script ---------- #!/bin/bash # Remove Files rm -f /location/of/file/myfile.txt ------------------------ ------ the cron job ------------- 30 16 * * * ./mycommand/script > /dev/null ------------------------ Where 30 16 = 4:30PM (16 is military time hour) (30 is the minute) (set these to the time you want it to run) ./mycommand/script = the shell script file you created that will be ran

Posted by case, 06-15-2008, 09:14 PM
I'd actually use a perl script. Perl makes handling errors a lot easier. The only reason I mention this is because automating deletion of files can be dangerous. You can copy the script up above into a file, and move that file into /etc/cron.daily that way you don't have to maintain crontab.

Posted by sysadminnick, 06-15-2008, 11:02 PM
If you don't mind me asking, what produces the file you need to delete every 24 hours?



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
red5 install problem (Views: 547)


Language:

Contact us