Linux Mount Points usage check with shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux Mount Points usage check with shell script
# 1  
Old 03-23-2016
RedHat Linux Mount Points usage check with shell script

Hi Everyone,

Just in need of your help again, I have managed to get a script to check the linux disk usage stuff. But wanted to tweak it little more to get the desired output.

Requirement:

Now its querying only one mount point, As its not saving in array instead calling it as variables. So i need each and every mount point to be check for its usage.
example mount points:
/
/dev/shm
/boot
/var

Code:
#!/bin/bash

LIMIT='80'

#Here we declare variable LIMIT with max of used space

DIR="( $(df -Ph | column -t | awk '{print $6}' | grep -v Mounted) )"   -------- here everything is saving as single variable as the output is a 5th column; but i need that to be processed line by line in the below for loop.

#Here we declare variable DIR with name of directory

MAILTO=' xyxz@abc.com'

#Here we declare variable MAILTO with email address

SUBJECT="$DIR disk usage"

#Here we declare variable SUBJECT with subject of email

MAILX='mailx'

#Here we declare variable MAILX with mailx command that will send email

which $MAILX > /dev/null 2>&1

#Here we check if mailx command exist

if ! [ $? -eq 0 ]

#We check exit status of previous command if exit status not 0 this mean that mailx is not installed on system

then

          echo "Please install $MAILX"

#Here we warn user that mailx not installed

          exit 1

#Here we will exit from script

fi

#To check real used size, we need to navigate to folder
for i in $DIR 
do
USED=$(df -Ph $i | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1)
done

#This line will get used space of partition where we currently, this will use df command, and get used space in %, and after cut % from value.

if [ "$USED" -gt "$LIMIT" ]

#If used space is bigger than LIMIT

then

      sudo du -sh ${DIR}/* | $MAILX -s "$SUBJECT" "$MAILTO"

#This will print space usage by each directory inside directory $DIR, and after MAILX will send email with SUBJECT to MAILTO

fi

-
Thiyags.
# 2  
Old 03-23-2016
script is broken, look at your loop and where the conditional check is.

Also, df is not du... combining the two may lead to unexpected results.

Consider the following (assumes Linux, but can be adjusted for others):

Code:
df -Phl -x tmpfs -x devtmpfs |
  sed -n -e 's/^\([/].*\)[ ]\+\([[:digit:].]\+[[:alpha:]]\)[ ]\+\([[:digit:].]\+[[:alpha:]]\)[ ]\+\([[:digit:].]\+[[:alpha:]]\)[ ]\+\([[:digit:].]\+\)[%][ ]\+\(.*\)/MAILTO=xyxz@abc.com;LIMIT=80;[ \5 -gt \$LIMIT ] \&\& echo -e "Filesystem: \1\\nSize:       \2\\nUsed:       \3\\nAvail:      \4\\nUse%:       \5\\nMounted:    \6" \| mailx -s "\1 usage over \$LIMIT %" \$MAILTO/p' |
  sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for logging cpu and memory usage of a Linux process

I am looking for a way to log and graphically display cpu and RAM usage of linux processes over time. Since I couldn't find a simple tool to so (I tried zabbix and munin but installation failed) I started writing a shell script to do so The script file parses the output of top command through... (2 Replies)
Discussion started by: andy_dufresne
2 Replies

2. Shell Programming and Scripting

Linux Shell Script to check for string inside a file?

This is what I have so far grep -lir "some text" * I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access. How can this be done? (3 Replies)
Discussion started by: mapleleafs89
3 Replies

3. Red Hat

Mount Points? How?

Hi folks, I have been asked to performed the following: Add the following new moint points systemA:/avp and SystemB:/usr/sap/trans to be the new linux server ZZZ How can I add those mount points and how those mount points can become another linuz server?:wall::wall::wall: (2 Replies)
Discussion started by: 300zxmuro
2 Replies

4. Shell Programming and Scripting

Shell script for Server Mount Point space check

Does anybody have anything I can use to help me out with this one? (4 Replies)
Discussion started by: lbone007
4 Replies

5. Shell Programming and Scripting

script to monitor mount points on linux box

Hi, the following shell script is not working on linux box sugeestions appreciated. FILE1=/tmp/check1.txt FILE2=/tmp/check2.txt df -k | awk '{if (NR != 1) print $5 $6}' > ${FILE1} awk -F"%" '{if ($1 > 90) print "Warning: Filesystem " $2 " over 90% threshold (" $1 "%)"}' ${FILE1} >... (7 Replies)
Discussion started by: prakash.gr
7 Replies

6. Shell Programming and Scripting

Shell Script to see the mount points.

Hi all, First of all I dont even know the ABC of scripting .. But now I want a Script to see the mount points of the file systems Can any body help plsssssssss :o (1 Reply)
Discussion started by: priky
1 Replies

7. Shell Programming and Scripting

test a script about mount points

Hi there, I would like people to test a script on as many situations as possible so we can find out errors and lacks. I wrote the script to help me work around mount points, especially when doing batch job on files (like backup) and to avoid duplicate operations through mount points. For... (2 Replies)
Discussion started by: chebarbudo
2 Replies

8. UNIX for Advanced & Expert Users

mount points

hi, I believe a mount point does not have to be a physical disk, but rather a logical one? Is this correct? if so, how can I find out if my mount points are on different physical disks? thanks (9 Replies)
Discussion started by: JamesByars
9 Replies

9. UNIX for Dummies Questions & Answers

Mount Points at reboot

How do I make a mount point reconnect at boot without editing /etc/fstab? Is there an option (or switch) to make this persistent when issuing the mount command from a client? (1 Reply)
Discussion started by: AIXdumb455
1 Replies

10. UNIX for Advanced & Expert Users

mount points

sometimes in Solaris 8 when I go to mount filesystems using either the mount command or by editing the /etc/vfstab, i get a nice little error message saying the the number of allowable mount points has been exceeded. I have read man pages until I am blue in the face and no where can I find what the... (3 Replies)
Discussion started by: manderson19
3 Replies
Login or Register to Ask a Question