Deleting files automatically, the condition in the month of creation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting files automatically, the condition in the month of creation
# 1  
Old 12-05-2001
Data Deleting files automatically, the condition in the month of creation

Hi all,
I'm newby in this great forum.
I'm working as an Intelligent Networks Administrator for a Fixed telephony company.
I want to write a script shell that helps me in my daily/weekly tasks.
A voice switch sends every hour a statistic file to a log directory.
By now, i've got more than 5000 files. I want to run a script that deletes files corresponding to the previous month (ie : if we are in December, this file will deletes all files created in Nov).
My idea to do that, as showing in the following lines of my script, is to list the files, after beeing sorted by the month, in a temporary file and read, line per line, this one to delete them.
My problem is how to wright my rm statement.
I don't know if my way of seeing it is the best one but please give me your lights.

.....
CURRENT_MONTH=`date | cut -f2 -d " "`
{
case "$CURRENT_MONTH" in
Jan) CURRENT_MONTH=Nov;;
Feb) CURRENT_MONTH=Dec;;
Mar) CURRENT_MONTH=Jan;;
Apr) CURRENT_MONTH=Feb;;
May) CURRENT_MONTH=Mar;;
Jun) CURRENT_MONTH=Apr;;
Jul) CURRENT_MONTH=May;;
Aug) CURRENT_MONTH=Jun;;
Sep) CURRENT_MONTH=Jul;;
Oct) CURRENT_MONTH=Aug;;
Nov) CURRENT_MONTH=Sep;;
Dec) CURRENT_MONTH=Oct;;
esac
}

`ls -l | grep "$CURRENT_MONTH" | cut -f20 -d " "` >> /home/aomp/log/tlogs/STScleanlog

if [ "$?" -eq 0 ]
then
while read /home/aomp/log/tlogs/STScleanlog
do
rm -f ????
done
....

Thanks guys.
# 2  
Old 12-05-2001
You could try something like:

find /home/aomp/log/tlogs/STScleanlog -ctime 30 -exec rm {} \;

This will remove any files older than 30 days (haven't been modified in 30 days actually).
# 3  
Old 12-08-2001
mo way,

Theres no way to do unoless the shell in in binary mode
# 4  
Old 12-10-2001
Hi AbRa-KaDabRa,

What do u mean?
I've try what doeboy sends me, and with littles modifications i could delete the files i wanted.
Pliz, explained me ur way.
FabioALex
# 5  
Old 12-10-2001
Yes AbRa-KaDabRa, could you please expand on what you mean.
I've only just become familiar with the find command and the following will work also.

## Remove files older than 1 yr.
find $xsardir -name sa\* -mtime +364 -type f -exec rm {} \;
## Remove directories older than 1 yr.
find $xsardir -name ???20?? -mtime +364 -type d -exec rm {} \;

Small Notation: The files/directories are secured 444, hence the use of -mtime.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script for Deleting files older than 14 days automatically

we need to have periodic clean up implemented in our sap directory \\sapds\PR1\int\scm\snp\outbound\snapshot. which needs unix script for Deleting files older than 14 days automatically in sap system unix os. (1 Reply)
Discussion started by: kvkreddy_b2w
1 Replies

2. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

3. Shell Programming and Scripting

deleting rows under a certain condition

there are 20 variables and I would like to delete the rows if 13th-20th columns are all NA. Thank you! FID IID aspirpre statihos fibrahos ocholhos arbhos betabhos alphbhos cacbhos diurehos numbcig.x toast1 toast2 toast3 toast4 ischoth1 ischoth2 ischoth3 ischoth4 101 101 1 1 1 1 1 2 1 2... (2 Replies)
Discussion started by: johnkim0806
2 Replies

4. UNIX for Advanced & Expert Users

why file automatically deleting in ftp server

Iam putting file in ftp server. iam doing ftp to transfer a file to ftp server but after sometime(10 sec) the file is automatically deleting in the ftp. Can i know why this happens. When my friend ftp the file to the same server , the file is not deleting aftersometime... it is there. Can... (1 Reply)
Discussion started by: nani1984
1 Replies

5. AIX

Deleting files older than 14 days automatically

Hi In my aix server under the location "/usr/sap/SAPXI/extract", I have a lot of log files. I need a script which is to be added in crontab so that the files and directories older than 14 days should get deleted automatically from the location "/usr/sap/SAPXI/extract". Please advise me.... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

6. HP-UX

deleting files for a particular month

Hi, I want to delete files of a particular month in a particular directory. Please tell me a script for this so that it will search a particular kind of file in that directory and delete them.I am using HP-UX. (1 Reply)
Discussion started by: adityam
1 Replies

7. UNIX for Dummies Questions & Answers

Deleting the files comparing the creation dates

Hi Gurus, I am new to unix. I have a requirement where i need to delete some files in a folder twice a week. Suppose i have a folder AAA. In that i have files from 01/04/2008 to 10/04/2008 I want to remove all the files except last 3 days i.e., 10,9th & 8th. Every week twice we want to... (2 Replies)
Discussion started by: pssandeep
2 Replies

8. Shell Programming and Scripting

command for deleting log files based on some condition

Hello, Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days. Any help will be highly appreciated. Thanks, Pulkit (4 Replies)
Discussion started by: pulkit
4 Replies

9. UNIX for Advanced & Expert Users

deleting files after the creation of a tar archive

Hi, I would modify to delete the files after creating the tar archive. How I can modify the following command: tar -cvvf logswitch.tar `find *.log* -mtime +5` It create a tar with files that are older than 5 days. (5 Replies)
Discussion started by: Minguccio75
5 Replies

10. Shell Programming and Scripting

Deleting file with last modified for 1 month

Hello... Any body, how to delete the files where last modified for 1 month, would you give some example. Sorry, im very newbie in scripting. Thanks. (4 Replies)
Discussion started by: blesets
4 Replies
Login or Register to Ask a Question