{"id":4280,"date":"2025-06-17T09:01:21","date_gmt":"2025-06-17T09:01:21","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4280"},"modified":"2025-06-17T09:01:23","modified_gmt":"2025-06-17T09:01:23","slug":"monitor-asm-diskgroup-usage","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/shell-scripts\/monitor-asm-diskgroup-usage\/","title":{"rendered":"Monitor ASM Diskgroup Usage"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This shell script monitors the space utilization of ASM diskgroups and sends an email alert when usage exceeds 90%. It&#8217;s essential for Oracle DBAs to stay ahead of potential storage issues in both standalone and RAC environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcdc Script: <code>asm_dg.sh<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>################################################################################\n# Title   : Monitoring ASM Diskgroup Usage\n# Script  : asm_dg.sh\n# Purpose : Checks ASM diskgroup space usage and sends email alerts\n#           if utilization exceeds 90%.\n#\n# Features:\n#   - Checks all diskgroups via v$asm_diskgroup\n#   - Sends a detailed usage report if threshold is breached\n#   - Easy integration into cron for automated monitoring\n#\n# Author  : W3Buddy\n# Version : 1.0\n################################################################################\n\n#!\/bin\/bash\n\n# --- Environment Variables ---\nexport ORACLE_HOME=\/oracle\/app\/oracle\/product\/12.1.0.2\/dbhome_1\nexport ORACLE_SID=PRODDB1\nexport PATH=$ORACLE_HOME\/bin:$PATH\n\n# --- Log File Location ---\nlogfile=\/export\/home\/oracle\/asm_dg.log\n\n# --- Run SQL and generate report ---\nsqlplus -s \"\/as sysdba\" > \/dev\/null &lt;&lt;EOF\nspool $logfile\nSET LINESIZE 150\nSET PAGESIZE 9999\nSET VERIFY OFF\n\nCOLUMN group_name FORMAT a25 HEAD 'DISKGROUP_NAME'\nCOLUMN state FORMAT a11 HEAD 'STATE'\nCOLUMN type FORMAT a6 HEAD 'TYPE'\nCOLUMN total_mb FORMAT 999,999,999 HEAD 'TOTAL SIZE (GB)'\nCOLUMN free_mb FORMAT 999,999,999 HEAD 'FREE SIZE (GB)'\nCOLUMN used_mb FORMAT 999,999,999 HEAD 'USED SIZE (GB)'\nCOLUMN pct_used FORMAT 999.99 HEAD 'PERCENTAGE USED'\n\nSELECT DISTINCT\n    name AS group_name,\n    state,\n    type,\n    ROUND(total_mb\/1024) AS total_mb,\n    ROUND(free_mb\/1024) AS free_mb,\n    ROUND((total_mb - free_mb)\/1024) AS used_mb,\n    ROUND((1 - (free_mb \/ total_mb)) * 100, 2) AS pct_used\nFROM\n    v\\$asm_diskgroup\nWHERE\n    ROUND((1 - (free_mb \/ total_mb)) * 100, 2) > 90\nORDER BY name;\n\nspool off\nexit\nEOF\n\n# --- Check and send alert if usage is above threshold ---\nif &#91; $(grep -c \"DISKGROUP_NAME\" $logfile) -gt 0 ]; then\n  mailx -s \"\ud83d\udea8 ASM DISKGROUP UTILIZATION ABOVE 90%\" info.w3buddy@gmail.com &lt; $logfile\nfi<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f Setup Instructions<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># ----------------------------------------------\n# 1. Create the script file\n# ----------------------------------------------\ncd \/export\/home\/oracle\nvi asm_dg.sh\n\n# (Paste the full script above into the file and save)\n\n# ----------------------------------------------\n# 2. Make the script executable\n# ----------------------------------------------\nchmod +x asm_dg.sh\n\n# ----------------------------------------------\n# 3. Test the script manually\n# ----------------------------------------------\n.\/asm_dg.sh\n\n# Check the output log for diskgroup usage:\ncat \/export\/home\/oracle\/asm_dg.log\n\n# ----------------------------------------------\n# 4. Schedule with cron (every 15 minutes)\n# ----------------------------------------------\ncrontab -e\n\n# Add this line:\n0,15,30,45 * * * * \/export\/home\/oracle\/asm_dg.sh >> \/tmp\/asm_dg_cron.log 2>&amp;1\n\n# ----------------------------------------------\n# 5. Confirm the cron entry\n# ----------------------------------------------\ncrontab -l<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This shell script monitors the space utilization of ASM diskgroups and sends an email alert when usage exceeds 90%. It&#8217;s essential for Oracle DBAs to stay ahead of potential storage issues in both standalone and RAC environments. \ud83d\udcdc Script: asm_dg.sh \u2699\ufe0f Setup Instructions<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,990],"class_list":["post-4280","cposts","type-cposts","status-publish","hentry","category-notes","category-shell-scripts"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/4280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}