Shell script partitions space monitor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script partitions space monitor
# 1  
Old 05-06-2009
Shell script partitions space monitor

Hello friends,

I'm newbie in shell scripting...
Until now i have this script:


Code:
 
#!/bin/sh
emailok = email1@domain.com
emailissue = email2@domain.com
limit="50"
df -h | grep -vE '^Filesystem' | awk '{print $1 " " $4 " " $5}'|while read val
do
partition=$(echo $val | awk '{print $1}')
echo "partition:$partition"
usedspace=$(echo $val | awk '{print $3}'| cut -d'%' -f1)
echo "usedspace:$usedspace%"
availspace=$(echo $val | awk '{print $2}')
echo "space available:$availspace"
echo "limit:$limit"
if [ $usedspace -gt $limit ]; then
echo "less than 50% space in $partition = $availspace"|mail -s "space info" $emailissue
else
echo "All ok." |mail -s "space info" $emailok
fi
done

the problem is that i have 2 partitions, and i receive 2 mails. If i have more than 2, then i will receive more mails.

what i want is to receive 1 mail, with 2 or more messages.

any ideas?

Last edited by john_doe; 05-06-2009 at 10:53 AM..
# 2  
Old 05-06-2009
nobody?
# 3  
Old 05-06-2009
Try this:

Code:
#!/bin/sh
emailok = email1@domain.com
emailissue = email2@domain.com
limit="50"
msgtxt=/tmp/email_msg.txt
msgok =/tmp/msg_ok.txt
touch $msgtxt
touch $msgok 

df -h | grep -vE '^Filesystem' | awk '{print $1 " " $4 " " $5}'|while read val
do
partition=$(echo $val | awk '{print $1}')
echo "partition:$partition"
usedspace=$(echo $val | awk '{print $3}'| cut -d'%' -f1)
echo "usedspace:$usedspace%"
availspace=$(echo $val | awk '{print $2}')
echo "space available:$availspace"
echo "limit:$limit"
if [ $usedspace -gt $limit ]; then
echo "less than 50% space in $partition = $availspace" >> $msgtxt
else
echo "All ok." > $msgok 
fi
done

if [ -s $msgtxt ]; then
cat $msgok | mail -s "space info" $emailok 
else
cat $msgtxt | mail -s "space info" $emailissue
fi


cheers,
Devaraj Takhellambam
# 4  
Old 05-06-2009
Thanks a lot...
I've did some changes...

Code:
 
!/bin/bash
emailok=email@domain.com
emailissue=email2@domain.com
limit="50"
msgissue=/tmp/msgissue.txt
msgok=/tmp/msgok.txt
touch $msgissue
touch $msgok
df -h | grep -vE '^Filesystem' | awk '{print $1 " " $4 " " $5}'|while read val
do
partition=$(echo $val | awk '{print $1}')
echo "partition:$partition"
usedspace=$(echo $val | awk '{print $3}'| cut -d'%' -f1)
echo "usedspace:$usedspace%"
availspace=$(echo $val | awk '{print $2}')
echo "space available:$availspace"
echo "limit:$limit"
if [ $usedspace -gt $limit ]; then
echo "less then 50% space in $partition .">$msgissue
else
echo "All ok.">$msgok
fi
done
if [ -s $msgissue ]; then
cat $msgok | mail -s "space info" $emailok
else
cat $msgissue | mail -s "space info" $emailissue
fi

now I get an empty mail, instead of a mail with issue message.... Smilie why?

Last edited by john_doe; 05-06-2009 at 11:45 AM..
# 5  
Old 05-06-2009
1.Can you check what are the contents of these files?
Code:
msgissue=/tmp/msgissue.txt
msgok=/tmp/msgok.txt

2. This should be a double redirect ( append mode) as this is in a loop.
Code:
echo "less then 50% space in $partition .">>$msgissue


cheers,
Devaraj Takhellambam
# 6  
Old 05-06-2009
1.I've already checked...

/tmp/msgok.txt has "All ok" message

/tmp/msgissue.txt is empty

2.Now it's doubled...

Still problems....

Code:
Null message body; hope that's ok

# 7  
Old 05-06-2009
Can you change the mail command to

Code:
mailx -s "space info"  $emailok < $msgok

and
Code:
mailx -s "space info" $emailissue < $msgissue


cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check used space for each partitions in Linux?

we are using Disk utilization and filesystem utilization seperately. In AIX using $lsvg rootvg datavg $lspv hdisk1 PHYSICAL VOLUME: hdisk1 VOLUME GROUP: datavg PV IDENTIFIER: 00f65eab7acabb17 VG IDENTIFIER 00f65eab00004c00000001567b60a848 PV STATE: ... (3 Replies)
Discussion started by: freeaac
3 Replies

2. Homework & Coursework Questions

Need shell script to monitor files

Hi Experts, I am not good in writing script. Just stared. I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of the... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

3. Shell Programming and Scripting

Shell script to monitor process with high CPU

Hi, Linux redhat 5.5 I need to write a kshell script that shows all the process that consume 100% CPU (or more. strange but there are time that top shows higger value that 100) and they are active more than 5 minute. The top command shows all the relevat information: The PID of the cpu ,... (0 Replies)
Discussion started by: yoavbe
0 Replies

4. UNIX for Advanced & Expert Users

Shell script to monitor cpu and VMstat, iostat

Hi , I am new to scripting. please help me out how to write a script to monitor cpu , vmstat, iostat in Redhat linux. we are doing the load test. Thanks in advance !!!! (1 Reply)
Discussion started by: saanvi
1 Replies

5. Shell Programming and Scripting

Script to monitor the disk space details in HP-UX

Hi, I need to monitor the disk space details in HP-UX . I need a command on how to display the information on below format File System Total_Space_KB Used_Space_KB Available_Space_KB %Used /u05 524288000 376235344 138799427 73% /u02 ... (0 Replies)
Discussion started by: ali560045
0 Replies

6. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

7. Shell Programming and Scripting

Need help on Linux script to monitor hard drive space

I'm new to Linux and have very limited experience with shell scripts in general. I am taking a class and I have to research online and come up with a shell script that monitors disk space. I also have to be able to explain it line by line. I've researched various sites and came across this shell... (3 Replies)
Discussion started by: wgreg23
3 Replies

8. Shell Programming and Scripting

script to monitor disk space usage

Some times my disk space is used upto 100% due to the application logs . So this script is to monitor the disk space usage and wall message to the users about the disk space usage if it exceeds the limit set in the script. Here for example the limit is set to 80%. This job is added in cron to... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

9. Shell Programming and Scripting

Shell script to monitor tmp folder for uploads

Hello, We have been having some issues with our users overwriting files, and then not having a backup. What I would love to do, is create a shell script to monitor /tmp, for uploads, and make a copy of the file they are trying to upload before the upload finishes. Is this possible at all? (6 Replies)
Discussion started by: mrfr0g
6 Replies
Login or Register to Ask a Question