Scripting help for rm log files from multiple dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting help for rm log files from multiple dir
# 1  
Old 06-01-2007
Scripting help for rm log files from multiple dir

Hi,

I'm quite new to scripting and need some help. I need to have one script that will check specific directories for files older than one month and then have the script delete them.

I have written the script below but it only does one directory. I don't quite know how to make it so it checks other directories as well.

#!/bin/sh

DIR=/export/home/Scripts/Batch/Ds/edsf/archive
export DIR

cd $DIR;/usr/bin/find . -mtime +31 -type f | /usr/bin/xargs rm -rf

Any help would be appreciated.
# 2  
Old 06-01-2007
Morgadoa,
See if this works for you:
Code:
find your_directory -type f -mtime +31 -exec rm -f {} \;

# 3  
Old 06-01-2007
Thanks for your reply. I thought of the find command but I have 8 specific directories that contain files to be deleted.
Do I execute a separate find for each dir path eg.

/export/home/Scripts/logs
/export/home/GLOBAL/logs
/export/home/Batch/logs

and so on..
# 4  
Old 06-01-2007
One find command only
Code:
cd /export/home
find Scripts/logs GLOBAL/logs Batch/logs -type f -mtime +31  | xargs rm -f

Jean-Pierre.
# 5  
Old 06-01-2007
Here is how you do it:
Code:
mDirList="/export/home/Scripts/logs"
mDirList=${mDirList}" /export/home/GLOBAL/logs"
mDirList=${mDirList}" /export/home/Batch/logs"
for mEachDir in ${mDirList}
do
  echo "Now deleting from "${mEachDir}
  find ${mEachDir} -type f -mtime +31 -exec rm -f {} \;
done

# 6  
Old 06-01-2007
Thanks for your help. Looks simple enough. I just wanted to confirm that the second and third line are just ammending to the variable mDirList in order to compile the list of directories- right?
# 7  
Old 06-01-2007
Yes, you can just keep adding as many directories as you want:
Code:
mDirList=${mDirList}" other_dir01"
mDirList=${mDirList}" other_dir02"
mDirList=${mDirList}" other_dir03"
...
mDirList=${mDirList}" other_dirNN"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

5. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

6. Shell Programming and Scripting

find string from multiple dir and redirect to new files

Hi, I am new to script and I want find one string from multiple files in diff directories and put that out put to new file. Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt Now I want write script to find the string... (8 Replies)
Discussion started by: Mahessh123
8 Replies

7. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

9. Shell Programming and Scripting

Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus, I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it: Requirement: ------------- I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log First of all this... (4 Replies)
Discussion started by: anshulinpc
4 Replies

10. UNIX for Dummies Questions & Answers

Scan Multiple Dir/Files

Hi gang, I have a project I would like to work on as I learn perl & ruby scripting. Maybe a big bite to chew off at first, but that's how I like to learn. Attack a real world problem. I would like to enhance our response to spam attacks here at our office where we run mail, dhcp, dns... (7 Replies)
Discussion started by: tonyd
7 Replies
Login or Register to Ask a Question