need help with disk check script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with disk check script
# 1  
Old 07-15-2007
CPU & Memory need help with disk check script

I wrote a script that checks particular device path directory which is full or more than 90% used, and will search older file inside and delete it. My code looks like this:

Code:
#!/usr/bin/ksh
ref=90

df -k | grep /cbmdata/00/gdd | tr -d '%' | \
while read a b c d e other
do

 if (( $e >= $ref )) && continue
 then
 line=`find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1`
    # echo $line
    rm -f $line
 fi

done

it works but not good, sometimes it only deletes only one file whereas I want it check the disk size and if more than 90 % in use go and delete another old file..it uses cronjob to timing...

Could you please advise me how can I make my script more robust or porfessional ? Thanks Smilie
# 2  
Old 07-15-2007
Try this (untested Smilie):

Code:
#!/usr/bin/ksh
ref=90

while [ 1 ] 
do
  df -k | grep /cbmdata/00/gdd | tr -d '%' | \
  read a b c d e other
  if (( "$e" >= "$ref" ))
  then
    line=`find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1`
    # echo $line
    rm -f $line
  else
    exit 0
  fi
done

Regards
# 3  
Old 07-15-2007
I tested it\ and seems to be working well/
I need to test for some time
Thanks Smilie
# 4  
Old 07-15-2007
Quote:
Originally Posted by xramm
I tested it\ and seems to be working well/
I need to test for some time
Thanks Smilie
You really should try to move the find command outside the while loop, it is the slowest part of your program and really only needs to be done once.

If your script was in ksh I would have suggested using a co-process and using 'read -p' however it is not, so you could do this by using a temporary file or a named pipe.
# 5  
Old 07-15-2007
ok, I ll try thank
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check disk space

I am trying a script which will alert if disk space crosses some threshold, i googled it and got some scripts already, but they are not working with my server. The problem is, my filesystem names are big, so the sizes are moving to the second line. just like below any ideas? thanks in advance... (8 Replies)
Discussion started by: karthikeayan
8 Replies

2. Homework & Coursework Questions

Looking to check disk space

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to check the disk space and if any portion disk space usage high then write to one file, later will... (5 Replies)
Discussion started by: Jasminshakoor
5 Replies

3. Solaris

How to check disk io

Hi, How to check disk io mount pointwise? I am working as Oracle DBA and want to check disk io as per mount point for adding new datafiles in tablesapce or change my redolog files to lowest disk I/O mount point. My all mount points are like /data1, /data2, /data3 ,,,,,. Can somebody tell me how... (1 Reply)
Discussion started by: rahul_switch
1 Replies

4. UNIX for Dummies Questions & Answers

check disk utility

Is there a UNIX check hard disk utility similar to the DOS utility chkdsk ? If there is one can it fix hard disk problems like checkdsk /f can with a DOS system? Where can I find these commands? (1 Reply)
Discussion started by: hatcity
1 Replies

5. Solaris

Disk space check

Hi, I have a question regarding finding free space on the disk of a solaris machine. Many mount points are available in my machine. Right now i am using df -b option to get the free disk space available. I have an assignment to check free space on the disk. I pass the directory as a... (6 Replies)
Discussion started by: raghu.amilineni
6 Replies

6. Shell Programming and Scripting

Script to check top 5 biggest disk space users

Hi all, I am needing a bash shell script to generate a list of the top 5 users using the most disk space. I am thinking that the du command would be used somehow but I am at a loss. Can anyone help? Thanks! (3 Replies)
Discussion started by: sytemx
3 Replies

7. Shell Programming and Scripting

Perl script to check free disk space

hello, I have to check the free space on the disk that would work both on Windows and Unix platform e.g on C: \ for Windows and / on Unix. I could use Unix command 'df ' ( my windows system has Unix emulator cygwin and could run 'df ' as well). But I'd like not to rely on system command but... (1 Reply)
Discussion started by: susja
1 Replies

8. Shell Programming and Scripting

Please help - disk space check script

I have a disk space check script that uses an exceptions file, the only issue with the script is that it does not work with values higher than the FSMAX=85 value. I have a file system that is at 92% and it doesn't change, so I would like to add it to the exceptions file. The exceptions file format... (0 Replies)
Discussion started by: maddhadder71
0 Replies

9. UNIX for Dummies Questions & Answers

Hard Disk Check

How can we check the number of hard disks (both internal & external) in a server, their capacity and serial number (5 Replies)
Discussion started by: muneebr
5 Replies

10. UNIX for Advanced & Expert Users

check disk

How I do to check disk not use in my server. Sun Solaris 2.8 df -k du |sort -rn But I want check disk and analyse a file system not used. Thanks for reply. (1 Reply)
Discussion started by: chris_carmo
1 Replies
Login or Register to Ask a Question