Looking to check disk space

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Need to check the disk space and if any portion disk space usage high then write to one file, later will check that file and inform thorough send mail.

  1. Relevant commands, code, scripts, algorithms:
#MSM2 Disk Check
DIR=/home/mform/healthcheck
rm $DIR/disk.txt
df -h  > $DIR/_tmp5
for i in  2 3 4 5 6 7 8 9
do
cat $DIR/_tmp5 | grep -v capacity | awk '{print $5}' | sed 's/%//g' >> $DIR/_tmp6
else
cat $DIR/_tmp5 | grep -v capacity | awk '{print $4}' | sed 's/%//g' >> $DIR/_tmp6
done
touch $DIR/_tmp7
for i in `cat $DIR/_tmp6`
do
if [ $i -ge 75 ];then
grep $i $DIR/_tmp5 >> $DIR/_tmp7
fi
done
chk=`cat $DIR/_tmp7 | wc -l`
if [ $chk -ne 0 ]; then
out=`cat $DIR/_tmp7`
echo "Please check the following disk usage"  `cat $DIR/_tmp7` > $DIR/disk.txt
else
echo "MSM disk usage is fine" > $DIR/disk.txt
fi
 
#rm $DIR/_tmp*
 
#sh $DIR/top_check.sh
MSMAPP1:/home/mform/healthcheck $ 
  1. The attempts at a solution (include all code and scripts):
    Presend disk usage is below
    MSMAPP1:/home/mform/healthcheck $ df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda2 9.5G 940M 8.1G 11% /
    /dev/sda9 189G 18G 162G 10% /data
    /dev/sda8 9.5G 2.4G 6.7G 27% /usr
    /dev/sda7 15G 553M 13G 5% /var
    /dev/sda6 15G 165M 14G 2% /tmp
    /dev/sda3 19G 13G 5.7G 69% /home
    /dev/sda1 289M 17M 258M 6% /boot
    tmpfs 7.9G 0 7.9G 0% /dev/shm
    10.50.11.86:/export/msmshare
    14T 220M 14T 1% /msmshare
    10.50.11.86:/export/backup
    2.0T 43G 2.0T 3% /Backup

  2. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

You have written some code that is absolutely unnecessary, if your intention is to get the list of file systems those have lets say above 50% utilization and mail it, then you can simply run:-

df -h | awk 'NR>1 { gsub("%","",$(NF-1)); if($(NF-1) ~ /^[0-9]/ && $(NF-1)>50) printf "%s%\t%s\n", $(NF-1), $NF; } ' | mailx -s "FS above 50%" user@xyz.com

Its not working sir, please check below error

mn1:/expo/orm $ df -h | awk 'NR>1 { gsub("%","",$(NF-1)); if($(NF-1) ~ /^[0-9]/ && $(NF-1)>50) printf "%s%\t%s\n", $(NF-1), $NF; } ' | mailx -s "FS above 50%" shjas@mail.com

awk: syntax error near line 1
awk: illegal statement near line 1

If your OS is Solaris / SunOS replace awk with nawk

Thank you, its working fine now.

i would like to create another script to check any process down if any process done store that process down in a variable to print. Other wise print all the process running. if any process down it will come below **** the servers not running****** . Can you help me

Servers Running********
AManager
Email Server
Alarm Server
SMS Server
MCP
Auto Server
JBoss Server
Service Server
Cleaner server
Servers Not Running****

How to do that is system-dependent. What's your system?