Forum Stats

  • 3,875,522 Users
  • 2,266,939 Discussions
  • 7,912,241 Comments

Discussions

Script to monitor FileSystems on Database Machine

Raul.Alvarenga
Raul.Alvarenga Member Posts: 98 Bronze Badge
edited Jan 6, 2019 5:40PM in Database Ideas - Ideas

Hi folks, below you will find and shell script to monitor usage percentage of a filesystem, you can schedule at Schedule Job or OS  Crontab

You can custom percentage (I use 85 %), FS List, email recipient, schedule time

The schedule can be:

43 20 * * *  /home/oracle/work/tamafs.sh ctgorap2 > /dev/null

the body script is:

#!/bin/bash

export PATH=/u01/app/oracle/product/11.2.0/dbhome_1/bin:/usr/sbin:$PATH

export SCRIPT_DIR=/home/oracle/work/scripts

export LOG_DIR=/home/oracle/work/log

CURR_DATE=`date '+%m/%d/%y_%H:%M'`

if [ -e ${LOG_DIR}/FS_Sync_status.txt ]

  then

    `rm   ${LOG_DIR}/FS_Sync_status.txt `

fi

if [ -e ${LOG_DIR}/FS_Sync_output.log ]

  then

    `rm ${LOG_DIR}/FS_Sync_output.log `

fi

for i in `ssh $1 df -h|awk '{ print $6 }'`

do

    # Convert the file size to a numeric value

  text="Mounted" 

  if [ "$i" = $text ] ;

  then

  text="Mounted"

  else

  for y in `ssh $1 df -h $i | awk '{ print $5 }'`

  do

  texto="Use%"

  if [ "$y" = $texto ] ;

  then

  text="Mounted"

  else

  filesize="${y//%}"

    # If any filesystem has less than 100k, issue an alert

   if [ $filesize  -gt 85 ];

   then

html_head="Subject: FS Check REPORT Hostname $1 for ${CURR_DATE}

\nMIME-Version: 1.0 \nContent-Type: text/html \nContent-Disposition: inline \n

<html>

<head>

<meta http-equiv=\"Content-Type\" content=text/html;

charset=\"UTF-8\">

<meta name=\"generator\" content=\"SQL*Plus 11.2.0\">

<style type=\"text/css\">

body {font:10pt Arial,Helvetica,sans-serif;

color:black; background:White;}

p {font:10pt Arial,Helvetica,sans-serif;

color:black; background:White;}

table,tr,td {font:10pt Arial,Helvetica,sans-serif;

color:Black; background:#f7f7e7;

padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;}

th {font:bold 10pt Arial,Helvetica,sans-serif;

color:#336699; background:#cccc99; padding:0px 0px 0px 0px;}

h1 {font:13pt Arial,Helvetica,Geneva,sans-serif;

color:#336699;text-decoration:underline;background-color:White;

border-bottom:1px solid #cccc99;

margin-top:0pt; margin-bottom:0pt;

padding:0px 0px 0px 0px;}

h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;

color:#336699; background-color:White;

margin-top:4pt; margin-bottom:0pt;}

a {font:9pt Arial,Helvetica,sans-serif;

color:#663300; background:#ffffff;

margin-top:0pt; margin-bottom:0pt; vertical-align:top;}

</style>

<title>

FS SYNC STATUS REPORT ${CURR_DATE}

</title>

</head>"

html_tail='<br><a><br>

<br> </a></body></html>'

salida="FileSystem $i esta demasiado lleno: $y  Usado"

echo -e $html_head >  ${LOG_DIR}/FS_REPORT.html

echo -e $salida >>  ${LOG_DIR}/FS_REPORT.html

echo $html_tail >>  ${LOG_DIR}/FS_REPORT.html

  sendmail -v [email protected] < ${LOG_DIR}/FS_REPORT.html

  fi

  fi

  done

  fi

done

Regards

1 votes

Active · Last Updated

Comments