Change Is Inevitable
  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)
Recent Posts
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation
Recent Comments
  • Kedar on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Jean-François Gagné on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Reggie on A Unique Foreign Key issue in MySQL 8.4
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
Home » shell script
Change Is Inevitable

Kedar Vaijanapurkar's Blog for MySQL, technology and various subjects

  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)

Browsing Tag

shell script

4 posts

How to Pause (Suspend) a process in Linux with kill signals

  • Kedar
  • January 9, 2018
In this post we will see how to pause (suspend) and start a linux process using signals (SIGTSTP and SIGCONT) via kill command.
View Post

10 useful shell script code snippets | Linux

  • Kedar
  • March 10, 2015
10+ useful code snippets of Linux shell scripts for how-to color, sendmail, log, change dir, parse parameters, loop, configuration file, switch..case and more.
View Post

MyDumpSplitter-Extract split database or tables from mysqldump

  • Kedar
  • February 11, 2010
The Mysqldumpsplitter can extract database, table, all databases, all tables or tables matching on regular expression from a mysqldump. It can produce the compressed output of sqls in specified directories.…
View Post

Simple Shell Script to Monitoring Disk Space on a Linux Machine

  • Kedar
  • January 11, 2009
This article explain a way to get a mail as soon as the disk usage reaches to its critical level to avoid issues later. To set a simple monitor on Linux /…
View Post
MySQL Podcast (Youtube)
RSS feed: MySQL Podcast (Spotify) MySQL Podcast (Spotify)
  • MySQL Major Version Upgrade Checklist (Zero Downtime Strategy)
    Upgrading MySQL major versions in production is never just a version bump - it’s a carefully planned process involving compatibility checks, replication strategy, testing, and controlled cut-over.In this episode, we walk through a practical MySQL Major Version Upgrade Checklist based on real-world DBA workflows. We are covering MySQL replication as base setup for upgrade. It […]
Search:
... ...
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation

5 responses to “Simple Shell Script to Monitoring Disk Space on a Linux Machine”

  1. Saurabh Awasthi Avatar
    Saurabh Awasthi
    July 26, 2020

    #!/bin/bash

    outputFile=”/mnt/d/ShellScript/umesh.log”
    outputFile1=”/mnt/d/ShellScript/umesh1.log”
    HTMLFile=”/mnt/d/ShellScript/filesystem.html”
    [ -f $outputFile ] && rm $outputFile
    [ -f $outputFile1 ] && rm $outputFile1
    [ -f $HTMLfile ] && rm $HTMLFile

    # fetch filesystem details
    df -hT >> ${outputFile}
    sed -n ‘2,$p’ ${outputFile} >> ${outputFile1}

    HTMLFileFunc() {
    echo “” >> $HTMLFile
    echo ” \n ” >> $HTMLFile
    echo “ Server filesystem Monitoring ” >> $HTMLFile
    echo ” ” >> $HTMLFile

    DateFlag=`date “+%H:%M %a, %b %d”`
    echo ” Report ran at @ $DateFlag” >> $HTMLFile
    echo “” >> $HTMLFile
    echo “” >> $HTMLFile
    echo “FileSystemTypeSizeUsedAvailUse%Mounted On” >> $HTMLFile

    while IFS=” ” read filesystem type size used avail uses mounted
    do
    used_memory=${uses%?}
    if [[ $((used_memory)) -le 20 ]]
    then
    color=’green’
    else
    color=’red’
    fi
    #echo $used_memory
    echo “${filesystem}${type}${size}${used}${avail}${used_memory}%${mounted}” >> $HTMLFile
    done < ${outputFile1}
    echo "” >> $HTMLFile

    }

    HTMLFileFunc

    Reply
  2. centos7 Avatar
    centos7
    December 27, 2018

    This works for me on CentOS 7:
    #!/bin/sh
    #Retrive disk space info
    df=`df -Pl | grep “^/dev” | awk ‘{print $5, $6}’ | sed “s/%//”`
    #Reference: df
    echo “$df”| while read percent fs
    do
    #If Disk Usage increases above 86% send an email.
    if [ $percent -ge 86 ] ; then
    #send an email.
    echo “Running out of space \”$partition ($percent%)\” on $(hostname) as on $(date)” | mail -s “Alert: Almost out of disk space $percent%” root
    fi
    done

    Reply
  3. George Avatar
    George
    March 17, 2010

    This works for me on RHEL 5.4
    #! /bin/ksh
    #
    ########################################################################################
    # This scripts monitors the disk space utilization and sends an email to the Admins if #
    # the amount of disk space for any file system reaches 90% or more. This script will #
    # run as an hourly cron job. #
    ########################################################################################
    df -h | grep -iv filesystem | while read LINE; do PERC=`echo $LINE | awk ‘{print $5}’ | sed -e ‘s/%//’`
    if [ $PERC -gt 90 ]; then
    echo “The Filesystem ${LINE} on `hostname`” |mail -s “Disk Space Alert” george.moran@aderas.com
    fi
    done

    Reply
  4. kedar Avatar
    kedar
    March 17, 2010

    Hi Vishwa,
    Idea in myscript was “grep”ing disk details from df command and using it in script.
    I’m not into Oracle yet (‘d be interested though) but you may for sure grep the oracle daemon or service information in the script.

    About services being stopped:

    For mysql if you want to check if it’s running or not we have:
    /etc/init.d/mysqld status
    Which will report the service status. I think Oracle must be having something like this.

    Meanwhile I Googled and found that normally people search for ORACLE_SID or pmon:
    ps -ef|grep $ORACLE_SID|grep -v grep|grep -v ora_|wc –l

    You may also grep for “pmon”, if that is not running you can say Oracle is down.

    Check below script:
    #!/bin/sh

    ret=`ps -fu oracle | grep ora_smon_ | grep -v grep | wc -l`
    echo $ret
    if [ $ret -eq 0 ] ; then
    echo “database down”
    # Run script here
    else
    echo “database up”
    fi

    I assume you should find this helpful: orafaq.com/wiki/Scripts.

    About unauthorized access:
    I’m not sure how will you detect that or what you meant by that!? If X enters as root user, how will you define that X is unauthorised? It’s better to stop unauthorized access by securing your OS settings than detect it later.

    Reply
  5. Vishwa Avatar
    Vishwa
    March 17, 2010

    I am using Oracle Apps 11i
    My OS is RHEL 4.6.

    I need to get a email alerts,

    when there is a critical issues like unauthorized access or services being stopped..

    How i can achieve this ..

    Reply
Change Is Inevitable
Designed & Developed by Code Supply Co.