Help needed to create a UNIX Space monitoring script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed to create a UNIX Space monitoring script
# 1  
Old 01-13-2014
Help needed to create a UNIX Space monitoring script

Hi All,

Its urgent.. pls help me out.. I want to create a KSH which should generate a report with the list of users and the files larger than 5 GB created by them in a direcorty and send autogenerated e-mail to them.
my input would be users list,directory path and the file size (say 5 GB)


Thanks in advance.
# 2  
Old 01-13-2014
What have you tried so far?
# 3  
Old 01-13-2014
Hello CarloM,

I have jus written the below script which will generate the top 10 large directories in the given path with size and sends an e-mail.

Likewise, I would like to have a script which takes users,path and file size as input and sends auto mail to those users in the output who has utilized more space in the given path/directory


Code:
 
#!/bin/ksh 
# Test if shell script is being invoked from directory where script resides or from a different directory
if [[ $(dirname ${0}) = . ]] then
  CURRDIR=$PWD
  PROGNAME=${0}
  PROGDIR=${CURRDIR}
else
  CURRDIR=${0}
  PROGNAME=$(basename ${CURRDIR})
  PROGDIR=$(dirname ${CURRDIR})
fi
CURRENT_DT=$(date +"%Y%m%d_%H%M%S")
CURRENT_DT_MAIL=$(date +"%m-%d-%Y")

CORE=""
 while [ "$CORE" == "" ]
 do
 printf "\n Please enter the path: "
 read CORE
  # echo "\n Mail sent.."
 if [[ ! -d $CORE || "$CORE" == "" ]]
 then
  CORE=""
  echo "\n Invalid path or Path does not exist! Please enter a valid path." 
 fi
 done
### create file to save the output ###
OFILE=${CURRDIR}/unix_message_test4.txt

### command to find the top 10 directories####
echo "\n Reading directory..."
echo ${CORE}
echo ${CURRDIR}
USRSMSG=`du -k ${CORE}|sort -rn|head -10 > ${OFILE}`
exec 1>> ${USRSMSG}
exec 2>&1
# mailx -s "****Urgent**** Action Required | Unix Space Utilization | ${CURRENT_DT_MAIL}" "test@email.com" < ${OFILE}
echo "Mail sent successfully.."

---------- Post updated at 08:20 AM ---------- Previous update was at 08:14 AM ----------

I have also tried this - to get the list of users in the unix box, and redirected theo/p to a file.
Code:
USERS=`ls -ld /home/*/ |cut -c 17-24 > ${CURRDIR}/users_list.txt`

Now am getting the below error when i tried to pass this users list in the for loop.
"m_input_5.ksh[72]: 0403-057 Syntax error at line 72 : `for' is not matched."
Code:
for users in `cat ${USERS}`
do
MAILTO="${users}@email.com"
CONTENT="${OFILE}"
SUBJECT="****Urgent**** Action Required | Unix Space Utilization | ${CURRENT_DT_MAIL}"
(
echo "To: ${MAILTO}"
echo "From: informatics@email.com"
echo "Subject: ${SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat ${CONTENT}
) | /usr/sbin/sendmail -t

# 4  
Old 01-13-2014
Ever thought of using quotas? It does simplify your life once correctly set...

Quote:
USERS=`ls -ld /home/*/ |cut -c 17-24 > ${CURRDIR}/users_list.txt`
Are you sure? What OS?
# 5  
Old 01-13-2014
By the way the "done" instruction keyword looks missing from the code block

Code:
for users in ...
do
....
 done

This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 01-13-2014
Might I suggest you look at the output from these:-
Code:
IFS=":"
cut -f1,5 -d ":" /etc/passwd | while read userid comment       # Loop for all userids & comments

du                                                             # Display usage

cd ~abc123                                                     # Change to the home directory of user abc123

find . -type f -exec ls -l {} \; | sort -nk 5                  # List out files from current directory and below sorted in ascending size

find / -type f -user userid -exec ls -l {} \; | sort -nk 5     # List out all files owner by nominated user in ascending size

I would agree that quota-setting could sort things out better, but you have to consider the risk of write failures when a quota is exceeded. Is that a problem?

You need to be clear on what you are searching for and why. Can you explain a little more?



I hope that these suggestions help.

Robin
Liverpool/Blackburn
UK
# 7  
Old 01-27-2014
Thanks all Smilie Finally,done with my script at the first level which is getting the directories as input,generates the result and sends it to the list of users via email. !!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance Monitoring script for UNIX servers

Hi, I have been working on writing an automated script that will run 24x7 to monitor the performance parameters like CPU,Memory,Disk I/O,Network,SWAP Space etc for all types of Unix servers ( HP-UX,AIX,SOLARIS,LINUX). Problem is I am confused with the commands top,prstat,vmstat,free,sar etc.... (4 Replies)
Discussion started by: ssk250
4 Replies

2. Shell Programming and Scripting

WPAR monitoring shell script suggestions needed

Hi All, This is for WPAR monitoring shell script, earlier opened thread was closed, had to open a new thread, as suggested I have used script as below, But am trying to get the output in below format, need suggestions with it. Below is the lswpar output, required output format. ... (7 Replies)
Discussion started by: aix_admin_007
7 Replies

3. Shell Programming and Scripting

help needed - log file monitoring script

hi Gurus, Need to pick your brains on this minor script project. I would like to continuously monitor a log file with sample log messages as below, and if PSOldGen percentage is either 99% or 100% for consecutively 10 times, alert someone. {Heap before gc invocations=46516: PSYoungGen ... (6 Replies)
Discussion started by: kenchen722
6 Replies

4. Shell Programming and Scripting

Disk Space Monitoring Script - OLD and NEW

It's the old thread "Disk Space Monitoring Script", modified for UNIX This is the new code: df -k | awk ' { if ( int($4) > 90) {subject = $1 " More than 90% disk usage. Used: " $4 email = "email@test.com" print subject cmd = "mailx -s \"" subject "\" " email cmd | getline... (4 Replies)
Discussion started by: dungureanu
4 Replies

5. Shell Programming and Scripting

script assistance needed - create an archive of INI files

First and foremost - me != unix bubba. Here is the situation. We have a box with data AND settings in the same directory path. (Data files aren't in the SAME directories as settings.) I need a script that generates a tarred-up archive of only the INI files with the directory structure. We... (2 Replies)
Discussion started by: hindesite
2 Replies

6. UNIX for Dummies Questions & Answers

Site monitoring help needed

Hi I have developed a website. Now i would like to monitor the IP address of machines who are accessing the server. The simplest possible solution to this that comes first into my mind is to use jsp inbuilt tags. <% out.print( request.getRemoteAddr() ); out.print( request.getRemoteHost()... (1 Reply)
Discussion started by: pinga123
1 Replies

7. Fedora

"integer expression expected" error with drive space monitoring script

Hi guys, I am still kinda new to Linux. Script template I found on the net and adapted for our environment: #!/bin/sh #set -x ADMIN="admin@mydomain.com" ALERT=10 df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output ... (2 Replies)
Discussion started by: wbdevilliers
2 Replies

8. Shell Programming and Scripting

Disk Space Monitoring Script

#!/bin/bash # Disk Space Monitoring for more than 95 % # and Sending Alerts by Mail if ; then `df -k |awk '$5 > 95 {print $1 " ----------- " $5}' |mailx -s "More than 95% disk usage in DEV" email@test.com'; else exit 0 fi I get the... (8 Replies)
Discussion started by: sriram003
8 Replies

9. Shell Programming and Scripting

Unix Port Monitoring Script

Is there a script which monitors a specific port and tells whethers its listening basically i am looking for a script which we can hardcode the port number there and hardcode an email address. It should alert to the email if the port is down. any idea.?plz (5 Replies)
Discussion started by: tintedwindow
5 Replies

10. UNIX for Dummies Questions & Answers

Help: Unix Monitoring Script

guys, i am creating a script to monitor our sun solaris unix server and email me the result of the script. currently, i am using the prtdiag -v command in the script to diagnose the hardware specs of the server. any suggestions on what else could i add like disk monitoring (using df)... ... (1 Reply)
Discussion started by: maztahvoodoo
1 Replies
Login or Register to Ask a Question