Operating System - HP-UX
1830850 Members
2199 Online
110017 Solutions
New Discussion

Script To delet the file periodically

 
Eric Jacklin
Regular Advisor

Script To delet the file periodically

Hi

we are using HP UX 11.11 and one of the incoming data folder contains files which is get created in the folder twice a day.Now My requirement is to delete the which was created 15 days back and it should happend every day.

So i would appriciate if you can provide me some script for the same.

Incase if you are not able to under stand my concern let me know i will agian try to explan it agin.


4 REPLIES 4
Yogeeraj_1
Honored Contributor

Re: Script To delet the file periodically

hi,

First, create your script which should like the following:

#!/bin/sh
#Script Name: /home/yogeeraj/scripts/purge_script.sh
DATAPATH=
CRITERIA="''"
find $DATAPATH -xdev -type f -mtime +15 -name $CRITERIA -exec rm -f {} \ ;
#End


then schedule the script using CRON.
#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
30 01 * * * /home/yogeeraj/scripts/purge_script.sh 1>
/home/yogeeraj/scripts/logfiles/output-purge_script.crn 2>/home/yogeeraj/scripts/logfiles/error-purge_script.crn
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************

if you need any further clarifications, please let us know

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Script To delet the file periodically

hi again,

You should also replace "\;" by "+" for performance.

so the script should be changed as follows:

find $DATAPATH -xdev -type f -mtime +15 -name $CRITERIA -exec rm -f {} +


sorry for inconveniences

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Eric Jacklin
Regular Advisor

Re: Script To delet the file periodically

Thanks this works
Eric Jacklin
Regular Advisor

Re: Script To delet the file periodically

Thanks again