The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help - disk space check script maddhadder71 Shell Programming and Scripting 0 05-08-2008 09:16 AM
Check the Disk usage Programmatically SriSri High Level Programming 2 09-20-2005 04:15 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 03:46 PM
Hard Disk Check muneebr UNIX for Dummies Questions & Answers 5 08-30-2005 05:37 PM
check disk chris_carmo UNIX for Advanced & Expert Users 1 05-10-2004 10:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-15-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
Arrow 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
  #2 (permalink)  
Old 07-15-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,330
Try this (untested ):


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 (permalink)  
Old 07-15-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
I tested it\ and seems to be working well/
I need to test for some time
Thanks
  #4 (permalink)  
Old 07-15-2007
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,240
Quote:
Originally Posted by xramm View Post
I tested it\ and seems to be working well/
I need to test for some time
Thanks
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 (permalink)  
Old 07-15-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
ok, I ll try thank
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0