1824212 Members
4148 Online
109669 Solutions
New Discussion юеВ

HOusekeeping files

 
Rajkumar_3
Regular Advisor

HOusekeeping files

Hai all,

I am rajkumar..Do any one have an idea about the Housekeeping files..

I have the environment like this..
Suppose i created a directory called /test.In that directory every day or for every week one file or some "n" files will be generated through another application..
So i have to delete that file using CRONTAB..And if any error occurs while deleting the file it has to be written to some logfile or it has to be promted to user about the status of the file..

Note: The file name is not constant..because the file will be generated with different name..It should be Parameterized..
The file name will be like
this : FILE<11111>.

Can any one help me by proving the Script ???

Thanks for the Advance in Help..

Regards
Rajkumar



Oracle DBA
7 REPLIES 7
Santosh Nair_1
Honored Contributor

Re: HOusekeeping files

You could use the find command to find files that are older than a set number of days and then delete those files, i.e.:

find /test -atime +3 -type f -print -exec rm -f {} \; > /tmp/rm.log 2&>1

This will delete any file that was access more that 3 days ago and will log the file name and any errors to /tmp/rm.log

-Santosh
Life is what's happening while you're busy making other plans
harry d brown jr
Honored Contributor

Re: HOusekeeping files

I'm sure we help. Post the script, and we'll take a look at it.
Live Free or Die
Michael Tully
Honored Contributor

Re: HOusekeeping files

Hi,

Using 'cron' to clean up filesystems is
quite normal. Usually it is either /tmp
or /var/tmp that have most of the
temporary files that need to be deleted,
but of course this depends on the application.

A simple thing could be from 'cron'

0 5 * * * find /tmp -name -mtime +7 | xargs rm

which will delete all files in /tmp that haven't been modified in 7 days. Changing the names of the files can be also done quite simply by using wildcards

HTH
-Michael
Anyone for a Mutiny ?
linuxfan
Honored Contributor

Re: HOusekeeping files

Hi,


You could do something simple like this, If you want to run this as a user, make sure you allow that user to run cronjobs by modifying /var/adm/cron/cron.allow

/Begin/

#!/usr/bin/sh

PATH=/usr/bin:/usr/contrib/bin:/usr/local/bin
DIR=/test
LOG_FILE=/tmp/delete_log
USER=testuser

# Listing the files that will be deleted
echo "These files will be deleted" > $LOG_FILE
find $DIR -atime +3 -exec ll {} \; >> $LOG_FILE

# Deleting the files that haven't been accessed for 3 days.
# Look at the man page of find for more options.

find $DIR -atime +3 -exec rm {} \; >> $LOG_FILE 2>&1

#Mailing the results to the user
mailx -s "Logfile Deletion" $USER < $LOG_FILE

#Cleaning up
rm $LOG_FILE

/End/

This should get you started.

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Rajkumar_3
Regular Advisor

Re: HOusekeeping files

Thank you all for the replies..

I have another query similar to this..

Suppose i have the Two servers one is "PRODUCT" server & "INVENTORY" server.

Daily the product server will FTP some files from the "INVENTORY" Server.

Once the file (test0000.dat) was transfered from the Inventory server to product server the file name was renamed to "X_TEST0000.DAT".

I created an Oracle Table called "PROFILE"
In that table i have 3 columns like
a) card_id
b) In_dir
c) Our_dir

Card_id:
-----------
In this column maximum 9 card_ids will be stored..For each 9 Card_ids the 9 directory paths will be stored in In_dir & Out_dir.

In_dir:
--------
In this column only the Inputfile name will be stored followed by the directory path..
For Eg: /test1/test0000.dat (to) /test1/test9999.dat

Out_dir:
--------
In this column only the Outputfile name will be stored followed by the directory path..
For Eg: /test1/test0000.dat (to) /test1/test9999.dat

So what i have to do is i have to write a shell script which runs automatically using Cronjob.

The shell script has to read the Two columns "In_dir" & "Out_dir" (ie Inputfile & Output File) from the oracle table and get the path for 9 Card_ids and check the file name start with "X_test0000.dat" to "X_test9999" in those directories and it has to be deleted for every 3 days only..If it found any file older than 3 days it has to be deleted for every 30 days...

Thanks for the Advance in Help

Regards
Rajkumar
Oracle DBA
Paula J Frazer-Campbell
Honored Contributor

Re: HOusekeeping files

Hi Rajkumar

Post your last question as a new question and do not forget to asign points to those who have helped you.

;-)

Paula
If you can spell SysAdmin then you is one - anon
Rajkumar_3
Regular Advisor

Re: HOusekeeping files

Hai Paulal,

I am very sorry about that..because i am little bit hurry to complete the assingned tasks to me...Appolizise....It will not repeat it again..

Ok Can any one help about ..Regarding the previous message My script has to collect the directory names from the two columns and that files has to be deleted for every 3 days starting with the name "X_"

Thanks for the advance in Help..

Rajkumar


Oracle DBA