Friday, March 2, 2018

UNIX: check CPU usage and disk usage

Script to check cpu usage

grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'

#!/bin/bash

limit=2
email_destination="whatever@gmail.com"
email_body="WARNING the CPU usage on server `hostname` exceeded the limit you set ($limit)%"
email_subject="WARNING cpu usage"

usage=`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}' | bc`

if echo $usage $limit | awk '{exit $1>$2?0:1}'
then
  echo -e $email_body | mail -s "$email_subject" $email_destination
  #echo 'alarm'
fi
_____________________________________________________

Disk space not updating in linux df -h after deleted files

ls -ld /proc/*/fd/* 2>&1 | fgrep '(deleted)'


restart the process that hold it

No comments:

UNIX: How to print column nicely using printf

[user@hostfwnms1-oam tmp]# cat b.sh printf "%-26s %-19s %-8s %-8s %-s %-s\n" HOSTNAME IP PING SNMPWALK 0-ok 1-fail for i in `cat n...