script to check large directory--help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to check large directory--help
# 15  
Old 04-23-2011
All,
Thanks .. Smilie

Now I am trying to create a generic script. but I am thinking that I am missing something in my script or I am not putting correct syntax somewhere. could any one please check and let me know where I am wrong .. If I am. Actually I used some old script and edited with my command.
Below is the script ..!!

Quote:
#!/bin/bash
# SYSTEM : monitor #
# PROGRAM NAME : monitor.ksh #
# #
# PURPOSE : This utility to space monitor in /AB/* folder project wise #
# #
# #
# #
# EXIT CODES : 0 - Program completed normally #
# >0 - Program fails #
################################################################################
################################################################################
# Initialize
################################################################################

data_base=/AB/*

DATA_DESK_TH_LIM=40
#------------------------------------------------------------------------------------------------
# Name : check_process_status
# Usage : check_process_status
# Description : This function checks whether the % of /AB/* Disk Spaces used is within Limit
# Exit Value : 0 on error 1 on success
#------------------------------------------------------------------------------------------------
function check_process_status {
EXIT_STATUS=1

df -k $data_base |grep % |awk '{print $4,$5}' |sed 's/%//g'| while read CMD_OUTPUT1;
do
uses=$(echo $CMD_OUTPUT1 | awk '{ print $1}' | cut -d'%' -f1 )
utilization=$(echo $CMD_OUTPUT1 | awk '{ print $2 }' )
if [ $uses -ge $DATA_DESK_TH_LIM ]
then
echo "------------------------------------------------------------------------------------------------"
echo " Spaces in $data_base is OVER THRESHOLD, \"$utilization ($uses%)\" on $(hostname) as on $(date)" >OP
echo "------------------------------------------------------------------------------------------------"
du -sk $utilization/*|sort -rn >>OP
EXIT_STATUS=0
fi
done
return $EXIT_STATUS
} # End of function check_process_status
###############################################################################
# Call script along with necessary parameters. #
###############################################################################

#-- Run the check_process_status
check_process_status
result=$?
if [ $result -eq 0 ]
then

echo "############################################################################################### ##"
echo " Script $0 started `date` "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~"
echo " WARNING : $data_base DISK Space in ONE or MORE Project Directory is OVER THRESHOLD"
echo "-------------------------------------------------------------------------------------------------"
echo " Script $0 execution completed `date` Error-Code $result"
echo "############################################################################################### ###"
echo " "
funEmailNotification "WARNING : /AB/* Space in ONE or MORE Project Directory is OVER THRESHOLD"
mail -s "Alert: Almost out of disk space $uses%" abc@@xyz.com <OP
exit $ERROR
else
echo "############################################################################################### ##"
echo " Script $0 started `date` "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~"
echo " NORMAL :/AB/* DISK Space size is UNDER THRESHOLD"
echo "-------------------------------------------------------------------------------------------------"
echo " Script $0 execution completed `date` Success-Code $result"
echo "############################################################################################### ###"
echo " "
#funEmailNotification "NORMAL : DISK Space size is UNDER THRESHOLD"
exit $SUCCESS
fi

Last edited by anshu ranjan; 04-23-2011 at 05:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check the files existence inside a directory.

Hello Folks, On Below Script, I want to apply condition. Condition that it check the directory for files if not found keep checking. Once directory have files and founded do the calculation and finish the code. Script to check the files existence inside a directory, If not then keep... (16 Replies)
Discussion started by: sadique.manzar
16 Replies

2. UNIX for Dummies Questions & Answers

Shell script to check the file sitting in the directory more than 10 hours

Hi, I require shell script to check for any pending files which are sitting in the particular directory for more than 10 hours. Please help me on this...Thank you. (5 Replies)
Discussion started by: kiruthiish
5 Replies

3. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

4. Shell Programming and Scripting

How to copy very large directory trees

I have constant trouble with XCOPY/s for multi-gigabyte transfers. I need a utility like XCOPY/S that remembers where it left off if I reboot. Is there such a utility? How about a free utility (free as in free beer)? How about an md5sum sanity check too? I posted the above query in another... (3 Replies)
Discussion started by: siegfried
3 Replies

5. UNIX for Dummies Questions & Answers

Is it better/possible to pause the rsyncing of a very large directory?

Possibly a dumb question, but I'm deciding how I'm going to do this. I'm currently rsyncing a 25TB directory (with several layers of sub directories most of which have video files ranging from 500 megs to 4-5 gigs), from one NAS to another using rsync -av. By the time I need to act ~15TB should... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

6. Red Hat

Empty directory, large size and performance

Hi, I've some directory that I used as working directory for a program. At the end of the procedure, the content is deleted. This directory, when I do a ls -l, appears to still take up some space. After a little research, I've seen on a another board of this forum that it's not really taking... (5 Replies)
Discussion started by: bdx
5 Replies

7. Shell Programming and Scripting

Using find in a directory containing large number of files

Hi All, I have searched this forum for related posts but could not find one that fits mine. I have a shell script which removes all the XML tags including the text inside the tags from some 4 million XML files. The shell script looks like this (MODIFIED): find . "*.xml" -print | while read... (6 Replies)
Discussion started by: shoaibjameel123
6 Replies

8. Shell Programming and Scripting

script to check for a directory in /home for all users

Following on from this post: https://www.unix.com/shell-programming-scripting/150201-simple-script-mount-folder-all-users-home.html and getting told off for bumping the thread:( Please could someone help me with a short script to check is a certain directory is present in /home for all users... (8 Replies)
Discussion started by: barrydocks
8 Replies

9. Shell Programming and Scripting

check the file in multiple Directory in a script

hi, i want to write the script to list atleast one file inside that directory eg: /home/Log/amp01 /home/log/amp02 . . . /home/log/amp..N want to see atleast one file inside the /home/log/amp01 .... amp(N) if it not there.. need to give that no file exists inside... (3 Replies)
Discussion started by: mail2sant
3 Replies
Login or Register to Ask a Question