Remember your dreams

Remember your dreams
Remember your dreams
Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Friday, February 28, 2020

Unix - Automatically notifiy when disk space is running low

It's good to be forewarned when one of your volumes or diskspace is running low before it actually runs out (100% used). I have seen many databases hang when any one of the volumes fills up for what ever reason. This script runs continuously in the background and checks for available disks space based on a threshold limit you set in the script.

Your system administrator will have their own method, but as the DBA you may want to know in advance of the system administrator and not have access to their tools.

First off I would like to thank Andy Denslow for the original check_diskspace code. I have made some modifications over time.

There are two scripts: run_check_diskspace.sh and check_diskspace.sh.

run_check_diskspace.sh is executed in the backgroup and every 30 minutes will call check_diskspace.sh.

check_diskspace.sh will perform the df -k command and if the threshold is met or passed will send you an email.

You can edit the sleep parameter to the disired time interval you wish to check. 1800 secs = 30 minutes.
Run in cron may be more desired.

First run_check_diskspace.sh
# ------------------------------------
# run_check_diskspace.sh
# ------------------------------------
#!/usr/bin/sh
x=0
while [ x -lt 1 ] ; do
/u01/app/oracle/scripts/monitor/check_diskspace.sh
sleep 1800
done


Now for check_diskspace.sh

# ------------------------------------
# check_diskspace.sh
# ------------------------------------

#!/bin/sh
############################

# This script is used to check the disk
# space of local filesystems and send
# alerts when the threshhold has been reached
#
# Original Base Code: Andy Denslow 1995
# Updated: Howard Hackworth 2004
############################
# -- At what point do we send page?
PAGELIMIT=95
# -- At what point do we send email warning of low diskspace?
LIMIT=85
## -- Uncomment the following one line for use with pager

# PAGER='1234567@somelocation.net'
# -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# -- Who do I send
email to?
MAIL='howard_hackworth@sgxpharma.com'
TEMP=/tmp/diskspace.tmp
df -k
l | sed "s/%/ /g" | sed "/Filesystem/d" | sed "/cdrom/d" >$TEMP
cat $TEMP while read LINE
do
SIZE=`echo $LINE | awk '{print $5}'`

if [ "$SIZE" -gt $LIMIT ]; then
SYSTEM=`echo $LINE | awk '{print $6}'`

echo "DISKSPACE WARNING *** `hostname`: $SYSTEM is $SIZE% full" | /usr/bin/mailx -s \
"Diskspace Warning `hostname`: $SYSTEM is $SIZE% full" $MAIL
elif [ "$SIZE" -gt "$PAGELIMIT" ]; then

## -- Uncomment for use with a pager instead of email:
## --
# echo "DISKSPACE CRITICAL *** `hostname`: $SYSTEM is $SIZE% full" | /usr/bin/mailx -s # "CRITICAL Diskspace ALERT! `hostname`: $SYSTEM is $SIZE% full" $PAGER
##
echo "`hostname`:$SYSTEM is $SIZE% full" | /usr/bin/mailx -s \
"CRITICAL Diskspace ALERT! `hostname`: $SYSTEM is $SIZE% full" $MAIL
fi
done
rm $TEMP
# -- end
check_diskspace.sh
# ----------------------------

To execute run from the command line the following command:
/scripts/monitor% ./run_check_diskspace.sh &

I also include this in my dbora script as follows:
su - $ORA_OWNER -c nohup /u01/app/oracle/scripts/monitor/run_check_diskspace.sh &
This is an example of the email you will receive when the disk threshold is reached.

Subject: Diskspace Warning hostname.yourdomain.com: /u02 is 91% full

DISKSPACE WARNING *** hostname.yourdomain.com: /u02 is 91% full


Thursday, November 10, 2016

Oracle runInstaller fails on Linux, Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set.

How to get Oracle's runInstaller to run on Linux or Unix environment using from Windows using Cygwin as an xterm emulator.

Download and install Cygwin

Launch Cygwin from the desktop icon


 Run startx from your Windows command line. "cmd" from your Search and run programs dialog.


$startx

Cygwin will launch and with multiple windows. In one of them run the xterm command


xterm from a Cygwin window


 


A new window will launch. This is the window you will now be working in. You will ssh to the machine where the Oracle installer is located.

Run the "ssh" command. Using the "-Y" option. Include the oracle username and the FQDN of the server.



$ssh -Y oracle@remote_hostname

Now you are connected to the remote server where Oracle was downloaded.
Set the Display variable.
I am using tcsh shell. ksh and bash uses different syntax to set variables. 

tcsh use this syntax

$setenv DISPLAY remote_hostname:10.0

sh shell you can use 
$DISPLAY=remote_hostname:10.0

You should be all set. Run the xdpyinfo command to verify your display is working.


/usr/bin/xdpyinfo


Now run Oracle Installer.

/oracle/app/install/12c/database/runInstaller &

 




 
 

Proactive Oracle DBA

This is a series of posts. I am working this to share some of the many scripts I schedule to automatically run to alert me of any current o...