Use below shell script to send email alert when tablespace reaches 80%. Make sure to replace "YOUR_TABLESPACE_NAME" with the tablespace name you would like to monitor:
#!/bin/bash# Set the tablespace name and thresholdTABLESPACE_NAME="YOUR_TABLESPACE_NAME"THRESHOLD=80# Get the current usage of the tablespaceUSAGE=$(echo "SELECT ROUND(A.BYTES/1024/1024) as USED_MB, ROUND((A.BYTES-NVL(B.BYTES,0))/1024/1024) as FREE_MB, ROUND((A.BYTES-NVL(B.BYTES,0))/A.BYTES*100) as PCT_FREE FROM (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) A, (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) B WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME(+) AND A.TABLESPACE_NAME='$TABLESPACE_NAME'" | sqlplus -s / as sysdba | grep -v USED_MB | awk '{print $3}')# Check if the usage is above the thresholdif [ $USAGE -ge $THRESHOLD ]; then # Send the email alert echo "Tablespace $TABLESPACE_NAME is $USAGE% full." | mail -s "Tablespace Alert: $TABLESPACE_NAME is $USAGE% full" your_email@example.comfi
Use below shell script to send email alert when tablespace reaches 80%. Make sure to replace "YOUR_TABLESPACE_NAME" with the tablespace name you would like to monitor:
#!/bin/bash # Set the tablespace name and threshold TABLESPACE_NAME="YOUR_TABLESPACE_NAME" THRESHOLD=80 # Get the current usage of the tablespace USAGE=$(echo "SELECT ROUND(A.BYTES/1024/1024) as USED_MB, ROUND((A.BYTES-NVL(B.BYTES,0))/1024/1024) as FREE_MB, ROUND((A.BYTES-NVL(B.BYTES,0))/A.BYTES*100) as PCT_FREE FROM (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) A, (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) B WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME(+) AND A.TABLESPACE_NAME='$TABLESPACE_NAME'" | sqlplus -s / as sysdba | grep -v USED_MB | awk '{print $3}') # Check if the usage is above the threshold if [ $USAGE -ge $THRESHOLD ]; then # Send the email alert echo "Tablespace $TABLESPACE_NAME is $USAGE% full." | mail -s "Tablespace Alert: $TABLESPACE_NAME is $USAGE% full" your_email@example.com fi