Need a shell script for FS maintenance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a shell script for FS maintenance
# 1  
Old 10-23-2009
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:

Code:
#!/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.


Last edited by zaxxon; 03-29-2010 at 04:17 AM.. Reason: code tags
# 2  
Old 10-23-2009
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  
Old 10-23-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Maintenance mode

i booted into maintenance mode boot -- -s from the console I got the Root password for system maintenance (control-d to bypass) I did control -d and then logged in it told me that I was booting into boot -s but after I did a control -d and logged in who -r shows ... (9 Replies)
Discussion started by: goya
9 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

maintenance script

Hi Guys i wonder if anyone can help. i want to create a script that checks multiple servers for disk space availible, cpu usage for past 24 hours. as well as check if all the hardware components are still doing their jobs. i will be doing this in the tcsh, can anyone help? OS = Sun Solaris 5.10... (2 Replies)
Discussion started by: brian112
2 Replies

6. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

7. SuSE

Library Maintenance

How are libraries created and maintained? I tried the following to add prog.o to an existing library ar -r library.so prog.o but the output is "File format not recognized", on the other hand nm --print-armap library.so does print a table of contents. (2 Replies)
Discussion started by: jgt
2 Replies

8. Solaris

Operation and Maintenance

I gurus of Solaris, I need to do a Procedure concerning in the Maintenance of Solaris Server. What are the parameters that I must be see Periodically in a Server. For example the space I (df -h) must be each week.- In this server exist a Database aplication (Oracle), and log's that increase or... (4 Replies)
Discussion started by: andresguillen
4 Replies

9. Solaris

Disk needs maintenance

Hi there, It's my first time here. I have an hard drive need a maintenance. here the result of metastat : Sun Microsystems Inc. SunOS 5.9 Generic May 2002 host2{11}: metastat d1: RAID State: Needs Maintenance Invoke: metareplace d1 c2t2d0s1 <new device> Interlace:... (3 Replies)
Discussion started by: Juterassee
3 Replies

10. UNIX for Advanced & Expert Users

System Maintenance

How do I go about doing this??? Is there something to it other than cleaning up useless files?? if you have knowledge concerning this, please give your suggestions also, is it possible or safe to compress an entire filesystem. how do you go about doing this??? any information is appreciated (7 Replies)
Discussion started by: IMPORTANT
7 Replies
Login or Register to Ask a Question