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
maintenance level lo-lp-kl AIX 2 07-31-2008 10:56 AM
maintenance on the SAN with AIX itik AIX 1 05-16-2008 02:07 PM
aix maintenance level manoj.solaris AIX 3 10-18-2007 04:46 PM
System Maintenance IMPORTANT UNIX for Advanced & Expert Users 7 04-10-2003 01:21 PM

Reply
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 10-23-2009
nibbsbitt nibbsbitt is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
Need a shell script for FS maintenance

Hi, I am not really good at shell scripting. I usually cut and paste from other scripts and customize it to do what I need. I am running Oracle 10g on AIX 5.3 machine and I need a script that monitors a filesystem, I would say at least every hour by cron, and if the filesystem hits above 80% full then I want the script to start deleting the oldest files in the filesystem first until the filesystem is back down to 50% full.

I have scripts that monitor the filesystem, but the whole 80 to 50% thing is where I am stumped. I have this script which I use to check the FS size and then email me when it gets past a certain percentage, was hoping I could modify that one maybe:

#!/bin/sh

. /proddb/u01/app/oracle/dbtools/dba_email_list.sh
#echo $DBA_EMAIL

S=/proddb/u01/app/oracle/dbtools/
cat /dev/null > $S/filesystem%
df -k | egrep '/oraaudit' | awk '$4 ~ /^96%/ || $4 ~ /^97%/ || $4 ~ /^98%/ || $4 ~ /^99%/ || $4 ~ /^100%/' > $S/filesystem%
egrep -s "/" $S/filesystem%
case $? in
0)
mail -s "Account Cust - file system above threshold on `hostname`" dbaemail@whatever.com < $S/filesystem%;;
*)
;;

esac



. Anyone able to assist me? I would really appreciate it. Thanks.

Jim


My guess would be that the part where I need to do the rm -rf to start deleting would go right where the mail part is.

  #2 (permalink)  
Old 10-23-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
The following would deal with the filesystem used thresholds:


Code:
FILESYSTEM=/path/subpath
if [ `df -k ${FILESYSTEM} | grep -v Use | awk '{ print $5 }' | sed 's/%//'` -gt 80 ]; then
  while [ `df -k ${FILESYSTEM} | grep -v Use | awk '{ print $5 }' | sed 's/%//'` -gt 50 ]; do 
    # do your file deleting here 
    echo "FS is greater than 50% full."
  done
else
  echo "Filesystem not too full yet"
fi

This assumes the output from:
df -k /path/subpath
looks like:

Code:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda5            109530708  31173952  72792648  30% /path

I'll leave the dangerous deleting of the oldest files bit to someone else!
  #3 (permalink)  
Old 10-23-2009
nibbsbitt nibbsbitt is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
Wow, thank you! I really appreciate you taking the time out to do that.

I use a script command like so to delete files older than 36 hours:

find /oraaudit -mtime +1.5 -exec rm -rf {} \;

I suppose it would be something like that but how to work in the fact that it should start with the oldest first is something I cant figure out.
Reply

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 06:21 AM.


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