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
# 8  
Old 01-27-2014
It would be polite to share your code so that others finding this thread have a suggested solution.



Thanks, in advance,
Robin
# 9  
Old 01-28-2014
Below is the script


Code:
#!/bin/ksh 
#############################################################################
# 7_script.ksh
# This script will generate unix space utilisation report
#############################################################################
### Date ########
CURRENT_DT=$(date +"%Y%m%d_%H%M%S")
CURRENT_DT_MAIL=$(date +"%m-%d-%Y")
TS=$(date +"%H%M%S")
# 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
### Create file to save the output ###
OFILE=${CURRDIR}/unix_message_test${TS}.txt
########### Getting path as input file and running a loop for getting the files greater than 1GB in the input paths########
IPATH=${CURRDIR}/unix_path.txt
for paths in `cat ${IPATH}`
do
USRSMSG=`find ${paths} -type f -size +1073741824c -ls >> ${OFILE}` #### files greater than 1GB
done
exec 1>> ${USRSMSG}
exec 2>&1
 
######## Sending the o/p as e-mail ##########
 
# USERS=`ls -ld /home/*/ |cut -c 17-24 > ${CURRDIR}/users_list.txt` ## to get the list of users from df-k
USERS=${CURRDIR}/users_list.txt ### input file which has the mail recipients###
for user in `cat ${USERS}`
do
MAILTO=${user}@abc.com
CONTENT=${OFILE}
SUBJECT="****Urgent**** Action Required | Unix Space Utilization | ${CURRENT_DT_MAIL}"
(
echo "To: ${MAILTO}"
echo "From: test@abc.com"
echo "Subject: ${SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: text"
echo "Content-Disposition: inline"
cat ${CONTENT}
) | /usr/sbin/sendmail -t
done
# mailx -s "****Urgent**** Action Required | Unix Space Utilization | ${CURRENT_DT_MAIL}" test@abc.com < ${OFILE}
echo "Mail sent successfully.."

This User Gave Thanks to anman0523 For This Post:
# 10  
Old 02-04-2014
Hi All,
Need your help again for the below issue

I have created a script which will give the files greater than 1GB with the userids,filesize,timestamp and the filename.

Code:
a 2312321 TS filename.txt
b 2423423 TS filename.txt
b 7676575 TS filename.txt
b 7567544 TS filename.txt
c 2435346 TS filename.txt
d 9786544 TS filename.txt

Now my objective is extract the userids and send mail with the files under their under name. i have used the cut cmd to get the userid's

Code:
cut -f 1 -d ' '

say am getting the o/p as below
Code:
a
b
b
b
c
d

Now i want to send e-mail to these users. when i run a for loop, multiple emails are sent to the same user.
(Eg) o/p expected
an e-mail with 3 lines for user 'b' to be sent only one time.

Please help me in sorting this out.
# 11  
Old 02-04-2014
You should really start a new thread for this as it is a separate query, but consider your logic:-
  • You want one email per id (assuming first field)
  • Do you want any detail from the report?
So:-
  • Capture the output to a file.
  • Get the unique values from the first column
  • For each user:-
    • Get all the detail from the file for that user
    • Send the mail.
Have a look at the sort command to get unique userids, and then think about how to get the detail for just the user required, searching from beginning of line with the user id and then a space.



Does this help?


Robin
# 12  
Old 02-07-2014
Thanks for the sugesstion Robin Smilie

I had used the
Code:
grep

command to solve this and it is working fine now.

I had got the unique users from the o/p using
Code:
uniq

command and grep'd the o/p file using this uniq users list

Below is the script
Code:
for user in `cat ${USERS}`
do
MAILTO="${user}@abc.com"
#echo `cat ${OFILE}| grep ${user}`
CONTENT=`cat ${OFILE}| grep ${user}`
SUBJECT="****Urgent**** Action Required | Unix Space Utilization | ${CURRENT_DT_MAIL}"
(echo "To: ${MAILTO}"
echo "From: `whoami`@abc.com" 
echo "Subject: ${SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: text"
echo "Content-Disposition: inline"
echo ${CONTENT}
) | /usr/sbin/sendmail -t
done


Last edited by Don Cragun; 02-07-2014 at 05:18 AM.. Reason: Get rid of font and size changes...
This User Gave Thanks to anman0523 For This Post:
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