<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RedHatVN Network &#187; disk full</title>
	<atom:link href="http://redhatvn.net/tag/disk-full/feed" rel="self" type="application/rss+xml" />
	<link>http://redhatvn.net</link>
	<description>Shared Linux problems</description>
	<lastBuildDate>Tue, 07 Sep 2010 08:08:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>UNIX Get An Alert When Disk Is Full</title>
		<link>http://redhatvn.net/unix-get-an-alert-when-disk-is-full</link>
		<comments>http://redhatvn.net/unix-get-an-alert-when-disk-is-full#comments</comments>
		<pubDate>Thu, 27 Aug 2009 08:41:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[disk full]]></category>

		<guid isPermaLink="false">http://redhatvn.net/?p=248</guid>
		<description><![CDATA[I want to get an alert when my disk is full under UNIX and Mac OS X? How do I set a a specified threshold and run the script via cron? The df command report file system disk space usage including the amount of disk space available on the file system containing each file name [...]]]></description>
			<content:encoded><![CDATA[<p>I want to get an alert when my disk is full under UNIX and Mac OS X? How do I set a a specified threshold and run the script via cron?</p>
<p><span id="more-248"></span></p>
<p>The df command report file system disk space usage including the amount of disk space available on the file system containing each file name argument. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.</p>
<div style="float: right; margin-top: 0px; margin-left: 5px;"><a title="See all UNIX related articles/faq" href="http://www.cyberciti.biz/faq/category/unix/"><br />
</a></div>
<p>Use df command and pass the -P option which make df output POSIX compliant (i.e. 512-byte blocks rather than the default. Note that this overrides the BLOCKSIZE specification from the environment).<br />
<code># df -P /</code><br />
OR<br />
<code># df -P /usr</code><br />
Sample Outputs:</p>
<blockquote><p>Filesystem    512-blocks     Used     Avail Capacity  Mounted on<br />
/dev/aacd0s1e  162491344 21988048 127503992    15%    /usr</p></blockquote>
<p>You can now simply grep /usr file system and print out used capacity:<br />
<code># df -P /usr | grep /usr | awk '{ print $5}' | sed 's/%//g'</code><br />
15<br />
Or assign value to a variable:<br />
<code># output=$(df -P /usr | grep /usr | awk '{ print $5}' | sed 's/%//g')<br />
# echo $output</code><br />
Under BASH or KornShell you <a href="http://www.cyberciti.biz/faq/tag/bash-array/">can use arrays indexed</a> by a numerical expression to make code small:<br />
<code># output=($(df -P /))<br />
# echo "${output[11]}"</code></p>
<h2>A Sample Shell Script</h2>
<blockquote><p><span style="color: #808080; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #808080; font-style: italic;"># Tested Under FreeBSD and OS X</span><br />
<span style="color: #007800;">FS=</span><span style="color: #ff0000;">&#8220;/usr&#8221;</span><br />
<span style="color: #007800;">THRESHOLD=</span><span style="color: #000000;">90</span><br />
<span style="color: #007800;">OUTPUT=</span><span style="color: #7a0874; font-weight: bold;">(</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #007800;">LC_ALL=</span>C <span style="color: #c20cb9; font-weight: bold;">df</span> -P <span style="color: #007800;">$<span style="color: #7a0874; font-weight: bold;">{</span>FS<span style="color: #7a0874; font-weight: bold;">}</span></span><span style="color: #7a0874; font-weight: bold;">)</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
<span style="color: #007800;">CURRENT=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">{</span>OUTPUT<span style="color: #7a0874; font-weight: bold;">[</span><span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">]</span><span style="color: #7a0874; font-weight: bold;">}</span> | <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&#8216;s/%//&#8217;</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
<span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$CURRENT</span> -gt <span style="color: #007800;">$THRESHOLD</span> <span style="color: #7a0874; font-weight: bold;">]</span> &amp;&amp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&#8220;$FS file system usage $CURRENT&#8221;</span> | mail -s <span style="color: #ff0000;">&#8220;$FS file system&#8221;</span> you@example.com</p>
<p>You need to modify syntax, if you are using KSH or TCSH / CSH instead of BASH. Save this script and run as <a href="http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/">a cron job</a>:<br />
 <code>@daily /path/to/your.df.script.sh<br />
</code></p>
<h2>GUI Notification</h2>
<p>Display warning dialog using /usr/bin/zenity</p>
<blockquote><p><span style="color: #808080; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #808080; font-style: italic;"># Tested Under FreeBSD and OS X</span><br />
<span style="color: #007800;">FS=</span><span style="color: #ff0000;">&#8220;/usr&#8221;</span><br />
<span style="color: #007800;">THRESHOLD=</span><span style="color: #000000;">90</span><br />
<span style="color: #007800;">OUTPUT=</span><span style="color: #7a0874; font-weight: bold;">(</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #007800;">LC_ALL=</span>C <span style="color: #c20cb9; font-weight: bold;">df</span> -P <span style="color: #007800;">$<span style="color: #7a0874; font-weight: bold;">{</span>FS<span style="color: #7a0874; font-weight: bold;">}</span></span><span style="color: #7a0874; font-weight: bold;">)</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
<span style="color: #007800;">CURRENT=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">{</span>OUTPUT<span style="color: #7a0874; font-weight: bold;">[</span><span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">]</span><span style="color: #7a0874; font-weight: bold;">}</span> | <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&#8216;s/%//&#8217;</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
<span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$CURRENT</span> -gt <span style="color: #007800;">$THRESHOLD</span> <span style="color: #7a0874; font-weight: bold;">]</span> &amp;&amp; /usr/bin/zenity  &#8211;warning  &#8211;<span style="color: #007800;">text=</span><span style="color: #ff0000;">&#8220;The disk $FS ($CURRENT% used) is almost full. Delete some files or add a new disk.&#8221;</span> &#8211;<span style="color: #007800;">title=</span><span style="color: #ff0000;">&#8220;df Warning&#8221;</p>
<p></span></p>
<div id="attachment_4764" style="width: 371px;"><a rel="attachment wp-att-4764" href="http://redhatvn.net/?attachment_id=4764"><img title="UNIX / Linux / OS X DF Command GUI Notification using zenity" src="http://files.cyberciti.biz/uploads/faq/2009/08/df-warning.png" alt="DF GUI Warning Notification " width="361" height="175" /></a><br />
DF GUI Warning Notification</div>
<p>Finally update your cronjob as follows (you need to use DISPLAY variable to display output window):</p>
<blockquote><p>36 19 * * *  DISPLAY=:0.0 /path/to/script.sh</p></blockquote>
</blockquote>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://redhatvn.net/unix-get-an-alert-when-disk-is-full/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->