Sponsored Content
Top Forums Shell Programming and Scripting Linux Mount Points usage check with shell script Post 302969500 by thiyagoo on Wednesday 23rd of March 2016 10:39:09 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
SWITCH_ROOT(8)						       System Administration						    SWITCH_ROOT(8)

NAME
switch_root - switch to another filesystem as the root of the mount tree SYNOPSIS
switch_root [-hV] switch_root newroot init [arg...] DESCRIPTION
switch_root moves already mounted /proc, /dev, /sys and /run to newroot and makes newroot the new root filesystem and starts init process. WARNING: switch_root removes recursively all files and directories on the current root filesystem. OPTIONS
-h, --help Display help text and exit. -V, --version Display version information and exit. RETURN VALUE
switch_root returns 0 on success and 1 on failure. NOTES
switch_root will fail to function if newroot is not the root of a mount. If you want to switch root into a directory that does not meet this requirement then you can first use a bind-mounting trick to turn any directory into a mount point: mount --bind $DIR $DIR SEE ALSO
chroot(2), init(8), mkinitrd(8), mount(8) AUTHORS
Peter Jones <pjones@redhat.com> Jeremy Katz <katzj@redhat.com> Karel Zak <kzak@redhat.com> AVAILABILITY
The switch_root command is part of the util-linux package and is available from https://www.kernel.org/pub/linux/utils/util-linux/. util-linux June 2009 SWITCH_ROOT(8)
All times are GMT -4. The time now is 12:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy