<?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>Web-In-Sight &#187; chkdir</title>
	<atom:link href="http://web-in-sight.nl/tag/chkdir/feed/" rel="self" type="application/rss+xml" />
	<link>http://web-in-sight.nl</link>
	<description>Inzicht in internet en werken</description>
	<lastBuildDate>Mon, 30 Jan 2012 09:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>My First Python: chkdir.py</title>
		<link>http://web-in-sight.nl/2007/11/03/my-first-python-chkdirpy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-first-python-chkdirpy</link>
		<comments>http://web-in-sight.nl/2007/11/03/my-first-python-chkdirpy/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 12:07:02 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[chkdir]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.gp-net.nl/2007/11/03/my-first-python-chkdirpy/en/</guid>
		<description><![CDATA[First of all I would like to thank my -fun to work with- colleague JW for his elaborate teachings on how to properly code in python. Thanks a lot! The script: chkdir.py Description The script emails differences on a directory&#8217;s &#8230; <a href="http://web-in-sight.nl/2007/11/03/my-first-python-chkdirpy/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>First of all I would like to thank my -fun to work with- colleague JW for his elaborate teachings on how to properly code in python. Thanks a lot!</p>
<p>The script: <a href="http://www.gerardjp.com/wp-content/uploads/2007/11/chkdir.py">chkdir.py</a></p>
<p><strong>Description</strong><br />
The script emails differences on a directory&#8217;s listing. So if you&#8217;re monitoring changes in a specific directory you can use this script. Run it under CRON every 5 minutes and on any changes you&#8217;ll get an email looking like this:</p>
<p><a href="http://www.gerardjp.com/wp-content/uploads/2007/11/screenshot-changes-in-home-gerard-files-python-chkdir-testdir-kontact1.png"><img class="alignnone size-full wp-image-535" title="screenshot-changes-in-home-gerard-files-python-chkdir-testdir-kontact1" src="http://www.gerardjp.com/wp-content/uploads/2007/11/screenshot-changes-in-home-gerard-files-python-chkdir-testdir-kontact1.png" alt="screenshot-changes-in-home-gerard-files-python-chkdir-testdir-kontact1" width="412" height="329" /></a></p>
<p><strong>Configuration</strong><br />
Not much. Change the email related variables in the config section in the header of the script. Example:</p>
<pre># Config section
MAILSERVER = 'localhost'
MAILFROM = 'somebody'
MAILTO = 'gerard'</pre>
<p><strong>Explanation</strong><br />
The script takes the absolute path to the directory that needs monitoring as the first argument. And an optional second argument called &#8216;verbose&#8217; if you want specifics. If all goes well during execution, and run without &#8216;verbose&#8217;, the script only outputs via email. The reason? This precludes your CRON daemon from doing unnecessary logging.</p>
<p>The previous listing of a directory, to which the new listing is compared, is stored in a file. The file is given the same name as the monitored directory. It has a suffix called &#8216;.dirlist&#8217; and the file is stored in the parent directory. See &#8216;Issues&#8217; at the end for more details.</p>
<p>The script only sends output to STDOUT during the initial stage when you start to monitor a directory.  The script cops out when: the parent directory is not writable, the given path does not exist, creating the first snapshot (dirlist) of a directory, etc. Since this is all done from the commandline at first, knowing what&#8217;s going at this stage is normal. After that the script turns quiet.</p>
<p><strong>Examples</strong><br />
Some startup failure messages:</p>
<pre>$ ./chkdir.py /tmp/
Sorry, I do not have permission to write in parent directory</pre>
<pre>$ ./chkdir.py /home/gerard/temp/testdir/
No previous listfile, created new one, will do diff on next run</pre>
<p>As said, after that it turns quiet, except when using &#8216;verbose&#8217;. Then your commandline output looks like this:</p>
<pre>./chkdir.py /home/gerard/temp/testdir verbose
New list
['Screenshot-GP-net \xe2\x80\xba Dashboard.png', 'GP-net \xe2\x80\xba Dashboard boe.png']

Old list
['Screenshot-GP-net \xe2\x80\xba Dashboard.png', 'GP-net \xe2\x80\xba Dashboard boe.png', 'Screenshot-Google.png']

Removed:
set(['Screenshot-Google.png'])</pre>
<p>The funky escaped values are unicode utf-8 characters. Like I said if you use verbose you get specifics. Not to worry though, any characters allowed in your file or directory names are correctly displayed when you get the output emailed (assuming your mail client supports them).</p>
<p><strong>Issues</strong><br />
Due to storing the file with the previous list in its parent directory it currently is not possible to monitor the &#8216;root&#8217; of you file system. A different approach would be to generate an md5 hash of the path and put the &#8216;.dirlist&#8217; file in &#8220;/tmp&#8221;. But that would result in people being able to obtain info on file system parts where they might not be allowed themselves.</p>
<p>Any suggestions on a better approach to store the previously made listing are welcome.</p>
<p>Regards,</p>
<p>Gerard.</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2007%2F11%2F03%2Fmy-first-python-chkdirpy%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2007/11/03/my-first-python-chkdirpy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

