Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simple Cron job?

Posted on 2003-03-05
2
Medium Priority
?
222 Views
Last Modified: 2013-12-15
Hi,

I am new to Linux having just installed it to run apache.
I need help to create a cron job that I can run every half an hour to delete all the files in a specific directory that are more than 30 minutes old.

Thanks in advance,

Paul.
0
Comment
Question by:desperado101
2 Comments
 
LVL 8

Accepted Solution

by:
heskyttberg earned 200 total points
ID: 8075137
Create a script like this:
delete_files.sh
#!/bin/bash
find $1 -type f -cmin -30 -exec rm -vf {} \;

#End of file

Put this in /usr/local/bin for instance.
Do chmod 750 or 755 on the file.

Do this:
crontab -e
As user you want tto setup crontab for:
Add the following line:
/30 * * * * {TAB} /usr/local/bin/delete_files.sh /my/dir/where/files/are

Regards
/Hans - Erik Skyttberg
0
 

Author Comment

by:desperado101
ID: 8075936
Lovely, thanks very much for your help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question