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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Delete script that runs in the background

I'm planning to write a delete script, and i found some good stuff @ EE
This script to be exactly:

find /data -ctime +30 -exec rm {} \;

this will delete all files that are older then 30 days in the folder      /data     right ?

If the above is correct i want to add one more thing. I don't want to execute the script myself once in a while but i want the script to keep running in the back ground, and check every 2 days (or every day) for files that are older then 30 days in the folder /folder.

Is this possible ?

thnx in advance


Sark
0
Mr-sark
Asked:
Mr-sark
  • 4
  • 2
1 Solution
 
sunnycoderCommented:
Hi Mr-sark,

This is very much possible .... set it up as a cron job

man 5 crontab

An example from the man page
================================================
       # run five minutes after midnight, every day
       5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1



Cheers!
sunnycoder
0
 
Mr-sarkAuthor Commented:
i'm new to this so could you maybe explain this line to me


5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1

and where do i put this file ?
0
 
Mr-sarkAuthor Commented:
back again, quess i found out how it works, so correct me if i'm wrong

if i take a look at /etc/crontab i'll see these lines:

[code]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[/code]

so i'll put the script

[code]
find /data -ctime +30 -exec rm {} \;
[/code]

in the file /etc/cron.daily

to let this file execute every dat ? righ ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sunnycoderCommented:
Hi Mr-sark,

>>man 5 crontab

/etc/crontab

Cheers!
sunnycoder
0
 
sunnycoderCommented:
You can do that too ... You can put your commands in a file and put that script in cron.daily
0
 
sunnycoderCommented:
Hi Mr-sark,

> in the file /etc/cron.daily
Its a directory :-) ... read the man page, it will help .. I cannot explain better than those guys

Cheers!
sunnycoder
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now