Disc space issues and purging of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Disc space issues and purging of files
# 1  
Old 02-08-2013
Question Disc space issues and purging of files

Hi All,

I am looking forward to create a unix shell script to purge the files.

The requirement is:

1) Do df -k and check the current space occupied for the /a1 folder.
2) If the space consumed is greater than 90 %, delete all the DEF* files from a subfolder /a1/archive.

Example:

df -k results in:
Code:
/dev/lv02         4194304    412292   91%    94883    10% /a1

Since the space is consumed > 90 % (91% in this case), the following files needs to be deleted:
Code:
/a1/ARCHIVE/DEF111.txt
/a1/ARCHIVE/DEF112.txt
/a1/ARCHIVE/DEF113.txt
/a1/ARCHIVE/DEF114.txt
/a1/ARCHIVE/DEF115.txt
/a1/ARCHIVE/DEF116.txt

Thanks in advance!

Last edited by Franklin52; 02-12-2013 at 03:06 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-08-2013
Ok, can you show us what you have tried?
# 3  
Old 02-08-2013
Quote:
Originally Posted by bipinajith
Ok, can you show us what you have tried and how you are stuck?
Since I have no prior unix experience, I have no script composed as of now.
# 4  
Old 02-08-2013
You can try something like below:
Code:
 
used=$( df -k "/a1" | awk 'NR > 1 { sub("%",X,$4); print $4 } ' )       # Get used percentage for folder: a1
 
if [ $used -gt 90 ]                                                     # Check if it is greater than 90
then
        echo rm -f /a1/ARCHIVE/DEF*.txt                                 # If yes, remove all /a1/ARCHIVE/DEF*.txt files
fi

Note: Remove highlighted echo if o/p looks good.
# 5  
Old 02-08-2013
Quote:
Originally Posted by bipinajith
You can try something like below:
Code:
 
used=$( df -k "/a1" | awk 'NR > 1 { sub("%",X,$4); print $4 } ' )       # Get used percentage for folder: a1
 
if [ $used -gt 90 ]                                                     # Check if it is greater than 90
then
        echo rm -f /a1/ARCHIVE/DEF*.txt                                 # If yes, remove all /a1/ARCHIVE/DEF*.txt files
fi

Note: Remove highlighted echo if o/p looks good.
Thanks Bipin!
I would test this script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fine Tune - Huge files/directory - Purging

Hi Expert's, I need your assitance in tunning one script. I have a mount point where almost 4848008 files and 864739 directories are present. The script search for specific pattern files and specfic period then delete them to free up space. The script is designed to run daily and its taking around... (19 Replies)
Discussion started by: senthil.ak
19 Replies

2. Solaris

Use files in place of real disc for asm

Hi I was trying to create files to be used as discs for asm configuration. I used the following steps mkdir -p /u02/asmdisks dd if=/dev/zero of=/u02/asmdisks/disk0 bs=1024k count=1000 dd if=/dev/zero of=/u02/asmdisks/disk1 bs=1024k count=1000 chown -R oracle:dba /u02/asmdisks chmod... (1 Reply)
Discussion started by: malikshahid85
1 Replies

3. Shell Programming and Scripting

purging of Files

Hello All, I want to delete the files based on the days. like, Files available under directory /abc want to delete if they are older than 15 days. Files available under directory /pqr want to delete if they are 7 days old and some files under directory /xyz should get deleted if they are... (5 Replies)
Discussion started by: ssachins
5 Replies

4. Shell Programming and Scripting

Shell script for purging the 3 days old files

Hi all, I try to write shell script to the below requirement. I have Hard coded the oratab location and take the list of databases from oratab and find out archive log locations for each database, and list more than 3 days old files for each location and purge those. ... (2 Replies)
Discussion started by: mak_boop
2 Replies

5. Ubuntu

Flash drive space issues

Hello, I have a 2 GB RealTek flash drive that has worked well in the past. It's about 1 year old but lately when I plug it into my Ubuntu Intrepid system it only shows 50 MB available even though there are no files on it: $ df -k /media/disk-1 Filesystem 1K-blocks Used... (1 Reply)
Discussion started by: mgb
1 Replies

6. Solaris

Ultra 10 - Copying Files From Disc After Booting Up With Recovery Disc?

Hello, I'm still learning unix and I have what is probably a simple question but I can't seem to find the question to. I have an Ultra 10 Sparc Server running solaris 8 and the drive may have crashed (I hope not). Currently, it appears some files in the /etc folder are missing. I have a backup... (1 Reply)
Discussion started by: ideffects
1 Replies

7. Shell Programming and Scripting

Error While Purging Files

find /filearchive/ -type f -mtime +7 -exec rm weblogs*.log {} \; This worked only if this comand is executed int he unix comand prompt, but when i put this in the shell script it is not recognizing the file.It says weblogs: No such file or directory Am i doing anything wrong here ? (4 Replies)
Discussion started by: svishh123
4 Replies

8. Shell Programming and Scripting

Purging a Set of Files

Hi Frineds, I want to delete a set of files which are older than 7 days from teh current date.I am totally enw to shell scripting, can anyone help me with a sample code to list out the files which are older and then remove them from the directory. Please help THanks Viswa (5 Replies)
Discussion started by: svishh123
5 Replies

9. Filesystems, Disks and Memory

Calculating Disc Space

Ok.... Can someone please point me in the right direction. I simply want to know how to take the results of a dfspace or df command and be able to know how to determine how much disk space is either used or remaining. 1$ dfspace Filesystem 512-blocks Free %Used Iused %Iused Mounted... (5 Replies)
Discussion started by: Docboyeee
5 Replies

10. UNIX for Dummies Questions & Answers

Calculating Disc Space

I need some help in determining disc space. I ran the following commands on my IBM RS6000 server and this is what I get # dfspace Filesystem 512-blocks Free %Used Iused %Iused Mounted on /dev/hd4 32768 19832 40% 1225 15% / /dev/hd2 802816 277256 66% ... (2 Replies)
Discussion started by: Docboyeee
2 Replies
Login or Register to Ask a Question