find full directory and delete old dated file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find full directory and delete old dated file?
# 1  
Old 07-07-2007
Question find full directory and delete old dated file?

I want to write a code that will look for a particular directory which is full or more than 95% used, and will search older file and delete it. My code looks like this:

Code:
df -k|while read f1 f2 f3 f4 f5 f6
do

if expr '$f5' -ge '95%' || continue
 then
 echo $f5
 else
 echo "there is no critical situation!"
fi
done

find . -name "*" -size +100k |sort -nr |tail -1\
#find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1\
while read line
 do rm -f $line
done

of course upper part doesn t work to comparison because I need to format 95% to decimal 95, but I couldn't . Can you please advise me a convert method?
# 2  
Old 07-07-2007
Code:
df -k | tr -d '%' | \
while read a b c d 
do
# do stuff 
done

will get remove the %
# 3  
Old 07-07-2007
can I put an else if there is no problem in this case ??

I tried your code and worked, thanks.
last updated code :

Code:
ref=95
rep=0

df -k | tr -d '%' | \
while read a b c d e other
do

if (( $e >= $ref )) || continue
then
 rep=$e
 echo $rep

fi
done

can I take an else to indicate there is no full disk?
Thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

2. Shell Programming and Scripting

Bash to delete file in directory

Will the below bash delete all the "snps.ivg" in the given directory? Thank you :) find N:\all_array\Samples -maxdepth 1 -type f -name "snps.ivg" -delete (6 Replies)
Discussion started by: cmccabe
6 Replies

3. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

4. UNIX for Dummies Questions & Answers

Extract directory from full file name?

I think I know what this is doing, but the 'eval' is confusing fname=$(echo ${lineItem} | awk 'BEGIN {FS=";"}{print $1}') fname=${fname%%+(])} fname=${fname##+(])} eval "fname=${fname}" The first line extracts the contents of the line preceeding the ";" 2nd & 3rd lines trim the value (I... (5 Replies)
Discussion started by: jdorn001
5 Replies

5. UNIX for Dummies Questions & Answers

Select the latest dated file-ksh script

Hello all!! I am new here and new in scripting! I want to write a ksh script to select the most recent file from a dir and use it in a variable. I have a directory with files named like: YYYMMDD A basic idea of the script I want to write is #!/usr/bin/ksh latest= latest_dated_file at... (2 Replies)
Discussion started by: chris_euop
2 Replies

6. UNIX for Dummies Questions & Answers

Create alias to daily dated directory

Hello, I wanted to see if there's a way to shortcut to a dated logs directory that changes daily...what I'm working with is something like this: > > > . . where the log directory is named yyyymmdd I've created a shortcut to get me to the /log directory but was... (2 Replies)
Discussion started by: mojowtm6
2 Replies

7. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

8. Shell Programming and Scripting

to find the file with full path

Hi, I have written this shell script: fl=`ls -1lrt $mylist | grep '\.xml$' | awk '{print $9}'` echo $fl (1) for i in $fl do for dir in $mylist do if then echo $dir/$i >> tmp (2) fi done done The mylist contains some directory names. The satement (1) gives the sorted list... (5 Replies)
Discussion started by: surjyap
5 Replies

9. Solaris

How to delete Directory and inside files using Find command

I am using the following Command to delete Directory with contents. But this command is deleting inside files only not directories. is there any change need in my command? find -type f -mtime +3 -exec rm -r {} \; Thanks (3 Replies)
Discussion started by: bmkreddy
3 Replies

10. Shell Programming and Scripting

Script to cd into newest (dated) FTP directory

I have written the following simple bash script. It logs onto an FTP site and then CDs into a directory that corresponds to the last business day. So for example the directory I would access today is 20060110 (2006 jan 10). I am currently taking today's date and subtracting 1, putting this... (3 Replies)
Discussion started by: steved
3 Replies
Login or Register to Ask a Question