<?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>Alain Kelder is a Giant Dork...</title>
	<atom:link href="http://giantdorks.org/alain/feed/" rel="self" type="application/rss+xml" />
	<link>http://giantdorks.org/alain</link>
	<description>Just another Giant Dorks Blogs weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:10:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Error Unable to open env file: /etc/default/locale: No such file or directory</title>
		<link>http://giantdorks.org/alain/error-unable-to-open-env-file-etcdefaultlocale-no-such-file-or-directory/</link>
		<comments>http://giantdorks.org/alain/error-unable-to-open-env-file-etcdefaultlocale-no-such-file-or-directory/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 16:09:13 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/error-unable-to-open-env-file-etcdefaultlocale-no-such-file-or-directory/</guid>
		<description><![CDATA[Some of my systems are logging this error:

su: pam_env(su:session): Unable to open env file: /etc/default/locale: No such file or directory

I already had the &#8220;locales&#8221; package installed, to create the file:

dpkg-reconfigure locales

Follow the prompts to choose your locale(s). Result:

cat /etc/default/locale


#  File generated by update-locale
LANG=en_US.UTF-8

]]></description>
			<content:encoded><![CDATA[<p>Some of my systems are logging this error:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">su: pam_env(su:session): Unable to open env file: /etc/default/locale: No such file or directory</pre></div></div>

<p>I already had the &#8220;locales&#8221; package installed, to create the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-reconfigure locales</pre></div></div>

<p>Follow the prompts to choose your locale(s). Result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>locale</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">#  File generated by update-locale
LANG=en_US.UTF-8</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/error-unable-to-open-env-file-etcdefaultlocale-no-such-file-or-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Append a line of text after a line matching a pattern</title>
		<link>http://giantdorks.org/alain/append-a-line-of-text-after-a-line-matching-a-pattern/</link>
		<comments>http://giantdorks.org/alain/append-a-line-of-text-after-a-line-matching-a-pattern/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 02:31:06 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=675</guid>
		<description><![CDATA[Let&#8217;s say we&#8217;ve got:

$ cat file.txt


1
2
3
4
5
6
7
blah
blah blah
append after me
blah bleh!
append after me
blah blah blah
bleeeh

This will add &#8220;new stuff&#8221; after every line that says &#8220;append after me&#8221;:

$ sed -i '/append after me/a new stuff' file.txt

Bingo:

$ cat file.txt


1
2
3
4
5
6
7
8
9
blah
blah blah
append after me
new stuff
blah bleh!
append after me
new stuff
blah blah blah
bleeeh

]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say we&#8217;ve got:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file.txt</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">blah
blah blah
append after me
blah bleh!
append after me
blah blah blah
bleeeh</pre></td></tr></table></div>

<p>This will add &#8220;new stuff&#8221; after every line that says &#8220;append after me&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/append after me/a new stuff'</span> file.txt</pre></div></div>

<p>Bingo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file.txt</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">blah
blah blah
append after me
new stuff
blah bleh!
append after me
new stuff
blah blah blah
bleeeh</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/append-a-line-of-text-after-a-line-matching-a-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to verify zip archives</title>
		<link>http://giantdorks.org/alain/shell-script-to-verify-zip-archives/</link>
		<comments>http://giantdorks.org/alain/shell-script-to-verify-zip-archives/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 21:40:30 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=669</guid>
		<description><![CDATA[This is similar to my little shell one liner to verify tar archives. Exit status of 0 means the archive is good, anything else means there&#8217;s a problem. Most of the problem archives I encountered had a status of 2, but a few 3&#8217;s and 9&#8217;s as well &#8212; see &#8220;man unzip&#8221; for explanation of [...]]]></description>
			<content:encoded><![CDATA[<p>This is similar to my little <a href="http://giantdorks.org/alain/shell-script-to-verify-tar-archives/">shell one liner to verify tar archives</a>. Exit status of 0 means the archive is good, anything else means there&#8217;s a problem. Most of the problem archives I encountered had a status of 2, but a few 3&#8217;s and 9&#8217;s as well &#8212; see &#8220;man unzip&#8221; for explanation of status codes. Using a while loop because some of the archive files names have spaces in them, which trips up the for loop:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.zip&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> f; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">unzip</span> <span style="color: #660033;">-t</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$f</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #007800;">err</span>=<span style="color: #ff0000;">&quot;$?&quot;</span>; <span style="color: #7a0874; font-weight: bold;">echo</span> checking <span style="color: #ff0000;">&quot;<span style="color: #007800;">$f</span>&quot;</span>; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$err</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$f</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> zip-check.list; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><span id="more-669"></span></p>
<p>Output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">2 ./1-02-cv-00319-RHB-JGS(170).zip
0 ./1-02-cv-00319-RHB-JGS(171).zip
2 ./1-02-cv-00319-RHB-JGS(172).zip
2 ./1-02-cv-00319-RHB-JGS(173).zip
0 ./1-02-cv-00319-RHB-JGS(174).zip
2 ./1-02-cv-00319-RHB-JGS(175).zip
0 ./1-02-cv-00319-RHB-JGS(176).zip
0 ./1-02-cv-00319-RHB-JGS(177).zip
2 ./1-02-cv-00319-RHB-JGS(178).zip
0 ./1-02-cv-00319-RHB-JGS(179).zip</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-script-to-verify-zip-archives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>High resolution with extra Compiz effects on Dell Mini 10 with Ubuntu 9.10 Karmic</title>
		<link>http://giantdorks.org/alain/high-resolution-with-extra-compiz-effects-on-dell-mini-10-with-ubuntu-9-10-karmic/</link>
		<comments>http://giantdorks.org/alain/high-resolution-with-extra-compiz-effects-on-dell-mini-10-with-ubuntu-9-10-karmic/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 07:25:11 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=661</guid>
		<description><![CDATA[Let me preface this post with a rant. In retrospect, I feel that getting this netbook with the Poulsbo chipset / Intel GMA500 video was a mistake since it&#8217;s been a major PITA. The little form factor has been more annoying than helpful. Should have gone with a larger laptop with a decent Nvidia or [...]]]></description>
			<content:encoded><![CDATA[<p>Let me preface this post with a rant. In retrospect, I feel that getting this netbook with the Poulsbo chipset / Intel GMA500 video was a mistake since it&#8217;s been a major PITA. The little form factor has been more annoying than helpful. Should have gone with a larger laptop with a decent Nvidia or ATI video card. There are reasons for why this chipset is such a bitch to live with and <a href="http://www.linux.com/news/hardware/desktops/166625-blaming-intel-for-how-the-world-is">sounds like it&#8217;s one of those situations where no one is at fault</a>. Fine, but after dumping quite a few hours on this thing since getting it, I frankly just don&#8217;t care. As a mere luser, I need a working computer whose video doesn&#8217;t keep breaking on every kernel and OS upgrade so I can live my life.</p>
<p>But, wasted hours aside, I just got it working again. I had the <a href="http://giantdorks.org/alain/ubuntu-running-in-low-graphics-mode-following-kernel-update/">nice 1366&#215;768 resolution previously working with Ubuntu 9.04</a>, but it wouldn&#8217;t let me turn on Compiz effects. A few days ago, swayed by promise of seemless iPhone 3GS syncing, I upgraded to Ubuntu 10.04, which broke video. Turns out, <a href="https://wiki.ubuntu.com/HardwareSupportComponentsVideoCardsPoulsbo">GMA500 support is not all there yet with Ubuntu 10.04 Lucid</a> and I forgot to research that before upgrading. So then I do a fresh install of Ubuntu 9.10 Karmic and <a href="https://wiki.ubuntu.com/HardwareSupportComponentsVideoCardsPoulsbo#karmic">follow the install steps on the Ubuntu Poulsbo Wiki</a>, only to find this did absolutely nothing. Turns out, it&#8217;s missing some critical steps. After scouring the web for a while and trying a bunch of settings, finally arrived at a configuration that works. Got the pretty resolution back and even got extra Compiz effects! This thing is a royal pain in the ass, but sure looks nice when it works. Anyway, here&#8217;s the config that&#8217;s working for me on Dell Mini 10 (aka Inspiron 1010).</p>
<p><span id="more-661"></span></p>
<p>First, we follow the <a href="https://wiki.ubuntu.com/HardwareSupportComponentsVideoCardsPoulsbo#karmic">Wiki</a> and add a repository and install some packages:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> add-apt-repository ppa:gma500<span style="color: #000000; font-weight: bold;">/</span>ppa <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
ak<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libdrm-poulsbo1 poulsbo-config poulsbo-driver-2d poulsbo-driver-3d psb-firmware psb-kernel-headers psb-modules xpsb-glx</pre></td></tr></table></div>

<p>Also install kernel sources, which the Wiki fails to mention:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> psb-kernel-source</pre></td></tr></table></div>

<p>Then we tell the kernel to leave some RAM for Compiz. Edit &#8220;/etc/default/grub&#8221; and set:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">GRUB_CMDLINE_LINUX=&quot;mem=786mb&quot;</pre></div></div>

<p>Be sure to update grub after:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-grub</pre></td></tr></table></div>

<p>Now we edit &#8220;/usr/bin/compiz&#8221; to tell Compiz that psb driver is not a bad guy after all by adding it to the list of drivers to whitelist:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">WHITELIST=&quot;nvidia intel ati radeon radeonhd i810 fglrx psb&quot;</pre></div></div>

<p>Then backup your /etc/X11/xorg.conf and replace it with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">Section &quot;ServerFlags&quot;
        Option &quot;DontZap&quot; &quot;False&quot;
EndSection
&nbsp;
Section &quot;Device&quot;
        Identifier &quot;Configured Video Device&quot;
        Option &quot;IgnoreACPI&quot;
        Option &quot;AccelMethod&quot; &quot;uxa&quot;
        Option &quot;MigrationHeuristic&quot; &quot;greedy&quot;
        Option &quot;NoDDC&quot;
        Option &quot;DRI&quot; &quot;on&quot;
        Option &quot;Tiling&quot; &quot;true&quot;
        Driver &quot;psb&quot;
EndSection
&nbsp;
Section &quot;DRI&quot;
        Mode 0666
EndSection
&nbsp;
Section &quot;Monitor&quot;
        Identifier &quot;Configured Monitor&quot;
EndSection
&nbsp;
Section &quot;Screen&quot;
        Identifier &quot;Default Screen&quot;
        Monitor &quot;Configured Monitor&quot;
        Device &quot;Configured Video Device&quot;
EndSection</pre></td></tr></table></div>

<p>Now reboot and enjoy your beautiful new screen (until next time it breaks). <img src='http://giantdorks.org/alain/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/high-resolution-with-extra-compiz-effects-on-dell-mini-10-with-ubuntu-9-10-karmic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Reject an email message with too many recipients with Postfix</title>
		<link>http://giantdorks.org/alain/reject-an-email-message-with-too-many-recipients-with-postfix/</link>
		<comments>http://giantdorks.org/alain/reject-an-email-message-with-too-many-recipients-with-postfix/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 04:16:10 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Postfix]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=657</guid>
		<description><![CDATA[The following config will reject a message when more than 10 recipients are in the TO: and/or CC: fields.
/etc/postfix/main.cf:

# restrict based on message header content 
header_checks = pcre:/etc/postfix/header_checks

/etc/postfix/header_checks:

/^To:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.
/^Cc:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.

Solution based on a post at linuxquestions.org.
]]></description>
			<content:encoded><![CDATA[<p>The following config will reject a message when more than 10 recipients are in the TO: and/or CC: fields.</p>
<p>/etc/postfix/main.cf:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># restrict based on message header content 
header_checks = pcre:/etc/postfix/header_checks</pre></div></div>

<p>/etc/postfix/header_checks:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/^To:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.
/^Cc:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.</pre></div></div>

<p>Solution based on a <a href="http://www.linuxquestions.org/questions/linux-server-73/postfix-content-filter-setup-to-reject-emails-with-too-many-recipients-in-to-field-680681/">post at linuxquestions.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/reject-an-email-message-with-too-many-recipients-with-postfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Little shell script to recursively check a site for broken links</title>
		<link>http://giantdorks.org/alain/little-shell-script-to-recursively-check-a-site-for-broken-links/</link>
		<comments>http://giantdorks.org/alain/little-shell-script-to-recursively-check-a-site-for-broken-links/#comments</comments>
		<pubDate>Mon, 24 May 2010 05:10:33 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Script]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=650</guid>
		<description><![CDATA[Needed a script for work to recursively spider one of our sites to check for problems and build a content inventory. As a side project, produced a little shell script that just checks links and produces a report by HTTP response code.

While script runs, it&#8217;ll produce a status report every 3 seconds of how many [...]]]></description>
			<content:encoded><![CDATA[<p>Needed a script for work to recursively spider one of our sites to check for problems and build a content inventory. As a side project, produced a little shell script that just checks links and produces a report by HTTP response code.</p>
<p><span id="more-650"></span></p>
<p>While script runs, it&#8217;ll produce a status report every 3 seconds of how many URLs it&#8217;s spidered so far. Example output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ak@gd:~$ ./check.url http://giantdorks.org/
Removing existing log..
213 URLs checked thus far
624 URLs checked thus far
&nbsp;
All done, calculating response codes..
&nbsp;
Response counts, sorted by HTTP code
    545 200
     62 302
     17 301</pre></div></div>

<p>Also useful to populate the Varnish cache as well as check effectiveness of the setup (run the script while running varnishhist on the web server). Then run it again to make sure you see mostly cache hits. In fact, I see all cache hits on the second run. Cache hits are pipes &#8220;|&#8221;, backend hits are pounds &#8220;#&#8221; &#8212; all pipes, no pounds make me happy.</p>
<p>Bad:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">1:15, n = 635                                me.sweet.box
&nbsp;
                                #
                                #
          |                     #
          |                     #
          |                     #
          |                     #
         ||                     #
         ||                     #
         |||                   ##
         |||                   ###
         |||               #   ###
+-----+-----+-----+-----+-----+-----+-----+-----+-----
|1e-6 |1e-5 |1e-4 |1e-3 |1e-2 |1e-1 |1e0  |1e1  |1e2</pre></div></div>

<p>Good:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">1:20, n = 634                                me.sweet.box
&nbsp;
        |
        |
        |
        |
        |
        |
        |
       |||
       |||
       |||
       ||||
       |||| 
       |||||
+-----+-----+-----+-----+-----+-----+-----+-----+-----
|1e-6 |1e-5 |1e-4 |1e-3 |1e-2 |1e-1 |1e0  |1e1  |1e2</pre></div></div>

<p>And here&#8217;s the script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># error handling</span>
<span style="color: #000000; font-weight: bold;">function</span> err_exit <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check if proper arguments are supplied</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Usage error!<span style="color: #000099; font-weight: bold;">\n</span> Please provide URL to check.<span style="color: #000099; font-weight: bold;">\n</span> Example: $0 http://example.com<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># normalize url for log name</span>
<span style="color: #007800;">url</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'s_https?://__;s/www\.//;s_/_._g;s/\.+/\./g;s/\.$//'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remove log if exists</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$url</span>.log <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Removing existing log..&quot;</span>
   <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$url</span>.log <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--spider</span> <span style="color: #660033;">-r</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$url</span>.log <span style="color: #000000; font-weight: bold;">||</span> err_exit <span style="color: #000000; font-weight: bold;">&amp;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>pgrep <span style="color: #660033;">-l</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">3</span>
  <span style="color: #007800;">total</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;HTTP request sent&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$url</span>.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$total</span> URLs checked thus far&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>All done, calculating response codes..&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Response counts, sorted by HTTP code&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^HTTP&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$url</span>.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$6}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-nr</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/little-shell-script-to-recursively-check-a-site-for-broken-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Responsibly download lots of files with wget</title>
		<link>http://giantdorks.org/alain/responsibly-download-lots-of-files-with-wget/</link>
		<comments>http://giantdorks.org/alain/responsibly-download-lots-of-files-with-wget/#comments</comments>
		<pubDate>Sat, 22 May 2010 19:31:20 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=642</guid>
		<description><![CDATA[The goal is to download pdf files from http://example.com/dir1/dir2/, where dir1 name is constant, but dir2 is a number between 100 and 499 (e.g. http://example.com/dir1/309/file258.pdf).
First, I&#8217;ll say that wget is a powerful tool and can place a burden on the site we&#8217;re grabbing data from (and probably get us banned as we&#8217;ll be perceived as [...]]]></description>
			<content:encoded><![CDATA[<p>The goal is to download pdf files from http://example.com/dir1/dir2/, where dir1 name is constant, but dir2 is a number between 100 and 499 (e.g. http://example.com/dir1/309/file258.pdf).</p>
<p>First, I&#8217;ll say that wget is a powerful tool and can place a burden on the site we&#8217;re grabbing data from (and probably get us banned as we&#8217;ll be perceived as carrying out a DOS attack). To avoid this, the example below will use a 5 second wait between downloads so as to not trouble the web server too much and keep the site usable for others.</p>
<p><span id="more-642"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> dir2 <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">100</span> <span style="color: #000000;">499</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-A</span> pdf <span style="color: #660033;">-w</span> <span style="color: #000000;">5</span> <span style="color: #660033;">--random-wait</span> <span style="color: #660033;">--retr-symlinks</span> <span style="color: #660033;">-k</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-U</span> <span style="color: #ff0000;">&quot;Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.19) Gecko/2010040118 Debian Lenny Firefox/3.0.19&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>example.com<span style="color: #000000; font-weight: bold;">/</span>dir1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$dir2</span><span style="color: #000000; font-weight: bold;">/</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Wget created a dir structure I don&#8217;t want, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">./example.com/dir1/309/file123.pdf</pre></div></div>

<p>Rename each file using parent directory name as part of the file name, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">309.file123.pdf</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.pdf&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">new</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s_^\./__;s_/_\._g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> renaming <span style="color: #007800;">$f</span> to <span style="color: #007800;">$new</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$f</span> <span style="color: #007800;">$new</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Then place all in a dir named example.com.dir1:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> example.com.dir1
<span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.pdf&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> moving <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$f</span> example.com.dir1<span style="color: #000000; font-weight: bold;">/</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/responsibly-download-lots-of-files-with-wget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily get the correct client IP with mod_rpaf</title>
		<link>http://giantdorks.org/alain/easily-get-the-correct-client-ip-with-mod_rpaf/</link>
		<comments>http://giantdorks.org/alain/easily-get-the-correct-client-ip-with-mod_rpaf/#comments</comments>
		<pubDate>Sat, 22 May 2010 12:24:51 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Debian]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=639</guid>
		<description><![CDATA[Let&#8217;s say you run a front end system like a reverse proxy, load balancer or http accelerator (e.g. big-ip, squid, pound, varnish, apache, nginx, etc), which pass dynamic requests to back end application servers, then you&#8217;re likely to have to deal with your applications seeing client requests as coming from the IP(s) of your front [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you run a front end system like a reverse proxy, load balancer or http accelerator (e.g. big-ip, squid, pound, varnish, apache, nginx, etc), which pass dynamic requests to back end application servers, then you&#8217;re likely to have to deal with your applications seeing client requests as coming from the IP(s) of your front end boxes. </p>
<p>This presents a slew of quality of life reducing issues, unless of course your back end system is Apache, in which case you can use mod_rpaf to make your life pleasant again.</p>
<p><span id="more-639"></span></p>
<p>Without it, you&#8217;d have to do painful things like patch your applications, which grab the client IP from the REMOTE_ADDR server variable, to use the X_FORWARDED_FOR header, if present, instead. For example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// If set, use IP provided by our front end rproxy</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$realclientip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$realclientip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>mod_rpaf solves this much more easily, it works as follows:</p>
<blockquote><p>It changes the remote address of the client visible to other Apache modules when two conditions are satisfied. First condition is that the remote client is actually a proxy that is defined in httpd.conf. Secondly if there is an incoming X-Forwarded-For header and the proxy is in its list of known proxies it takes the last IP from the incoming X-Forwarded-For header and changes the remote address of the client in the request structure. </p></blockquote>
<p>If you&#8217;re on Debian (or one of its derivatives &#8212; Ubuntu, etc), get it with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libapache2-mod-rpaf</pre></div></div>

<p>Modify &#8220;/etc/apache2/mods-available/rpaf.conf&#8221; to include IP(s) of your front end boxes and enable with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ a2enmod rpaf
ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ apache2ctl <span style="color: #660033;">-t</span>
ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ apache2ctl restart</pre></div></div>

<p>Now, mod_rpaf will grab IP from X_FORWARDED_FOR header and place it in REMOTE_ADDR server variable. You can verify with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$clientip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$remoteaddr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xforwardedfor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; &lt;li&gt;HTTP_CLIENT_IP:  <span style="color: #006699; font-weight: bold;">$clientip</span>&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; &lt;li&gt;REMOTE_ADDR:  <span style="color: #006699; font-weight: bold;">$remoteaddr</span>&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; &lt;li&gt;HTTP_X_FORWARDED_FOR:  <span style="color: #006699; font-weight: bold;">$xforwardedfor</span>&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Geesus, that was easy. Gotta love Apache with its plethora of delicious modules. Using a distro like Debian that makes them super easy to get is nice too. Now, I can stop patching apps and go ride a board.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/easily-get-the-correct-client-ip-with-mod_rpaf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insert line numbers in files painlessly with nl</title>
		<link>http://giantdorks.org/alain/insert-line-numbers-in-files-painlessly-with-nl-2/</link>
		<comments>http://giantdorks.org/alain/insert-line-numbers-in-files-painlessly-with-nl-2/#comments</comments>
		<pubDate>Fri, 21 May 2010 19:41:29 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[coreutils]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=636</guid>
		<description><![CDATA[Was trying to figure out how to insert line numbers into a huge file with sed or awk, then stumbled across &#8220;nl&#8221;, a sweet little baby that comes with GNU coreutils and numbering files is what it does for a living. GNU coreutils is full of gems!
Boring:

ak@gd:~$ cat file
blah
blah blah
bleh blah

Awesome:

ak@gd:~$ cat file &#124; nl [...]]]></description>
			<content:encoded><![CDATA[<p>Was trying to figure out how to insert line numbers into a huge file with sed or awk, then stumbled across &#8220;nl&#8221;, a sweet little baby that comes with GNU coreutils and numbering files is what it does for a living. GNU coreutils is full of gems!</p>
<p>Boring:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #c20cb9; font-weight: bold;">file</span>
blah
blah blah
bleh blah</pre></div></div>

<p>Awesome:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>gd:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">nl</span> <span style="color: #660033;">-n</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-w1</span> -s\<span style="color: #000000; font-weight: bold;">|</span>
<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">|</span>blah
<span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">|</span>blah blah
<span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">|</span>bleh blah</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/insert-line-numbers-in-files-painlessly-with-nl-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Display non-printing characters with cat and replace with sed</title>
		<link>http://giantdorks.org/alain/display-non-printing-characters-with-cat-and-replace-with-sed/</link>
		<comments>http://giantdorks.org/alain/display-non-printing-characters-with-cat-and-replace-with-sed/#comments</comments>
		<pubDate>Fri, 21 May 2010 05:24:14 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Sed]]></category>
		<category><![CDATA[cat]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=628</guid>
		<description><![CDATA[Got a csv file created with Open Office from a Microsoft Excel file. It contains characters which in less show up as &#8220;^K&#8221; (caret upper case K), which trip up the shell and vi. One way to get rid of them is to display them with &#8220;cat &#8211;show-nonprinting&#8221; and then replace with sed:

cat -v file [...]]]></description>
			<content:encoded><![CDATA[<p>Got a csv file created with Open Office from a Microsoft Excel file. It contains characters which in less show up as &#8220;^K&#8221; (caret upper case K), which trip up the shell and vi. One way to get rid of them is to display them with &#8220;cat &#8211;show-nonprinting&#8221; and then replace with sed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\^K//g'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/display-non-printing-characters-with-cat-and-replace-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to enumerate titles and chapters of a dvd and rip the longest one into avi using mencoder</title>
		<link>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-the-longest-one-into-avi-using-mencoder/</link>
		<comments>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-the-longest-one-into-avi-using-mencoder/#comments</comments>
		<pubDate>Tue, 18 May 2010 21:27:30 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Awk]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Sed]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[lsdvd]]></category>
		<category><![CDATA[mencoder]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=623</guid>
		<description><![CDATA[BASH script to enumerate titles and chapters of a dvd and rip the longest one into avi using mencoder. DVD device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/).
To rip all titles and chapters, try this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# script to identify and rip the longest title of a dvd into [...]]]></description>
			<content:encoded><![CDATA[<p>BASH script to enumerate titles and chapters of a dvd and rip the longest one into avi using mencoder. DVD device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/).</p>
<p>To rip all titles and chapters, try <a href="http://giantdorks.org/alain/shell-script-to-enumerate-titles-and -chapters-of-a-dvd-and-rip-each-into-a-separate-avi-using-mencoder/">this</a>.</p>
<p><span id="more-623"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># script to identify and rip the longest title of a dvd into xvid avi</span>
<span style="color: #666666; font-style: italic;"># dvd-device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/)</span>
<span style="color: #666666; font-style: italic;"># expects dvd as $1 and dvd name as $2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># error handling</span>
<span style="color: #000000; font-weight: bold;">function</span> err_exit <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Confirm two arguments were passed</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Usage error! Need two arguments.<span style="color: #000099; font-weight: bold;">\n</span> Example: $0 dvd-device My.DVD<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check if VIDEO_TS exists</span>
<span style="color: #007800;">ddir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$1/VIDEO_TS&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s_/\+_/_'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ddir</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Error!<span style="color: #000099; font-weight: bold;">\n</span> Can't find <span style="color: #007800;">$ddir</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">log</span>=<span style="color: #ff0000;">&quot;dvd2xvid-longest.log&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remove log if exists</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$log</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Removing existing <span style="color: #007800;">$log</span>..&quot;</span>
   <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># test lsdvd</span>
lsdvd <span style="color: #660033;">-x</span> $<span style="color: #000000;">1</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># get longest track</span>
<span style="color: #007800;">title</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>lsdvd <span style="color: #660033;">-x</span> $<span style="color: #000000;">1</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;Longest track&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$3}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># get longest chapter of the longest title</span>
<span style="color: #007800;">chapter</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>lsdvd <span style="color: #660033;">-c</span> -t<span style="color: #007800;">$title</span> $<span style="color: #000000;">1</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\s\+//'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;Chapter:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k4r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'Chapter: '</span> <span style="color: #ff0000;">'{print$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">','</span> <span style="color: #ff0000;">'{print$1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># log date</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(date)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># real work starts here</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> divx2pass.log frameno.avi <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #666666; font-style: italic;"># define source</span>
<span style="color: #007800;">SRC</span>=<span style="color: #ff0000;">&quot;dvd://<span style="color: #007800;">$title</span> -chapter <span style="color: #007800;">$chapter</span> -dvd-device $1 -alang en&quot;</span>
<span style="color: #666666; font-style: italic;"># audio pass</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started apass&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-oac</span> mp3lame <span style="color: #660033;">-lameopts</span> <span style="color: #007800;">mode</span>=<span style="color: #000000;">2</span>:cbr:<span style="color: #007800;">br</span>=<span style="color: #000000;">96</span>:<span style="color: #007800;">vol</span>=<span style="color: #000000;">0</span> \
<span style="color: #660033;">-ovc</span> frameno <span style="color: #660033;">-o</span> frameno.avi <span style="color: #007800;">$SRC</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> \
<span style="color: #666666; font-style: italic;"># video pass 1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started vpass1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-sws</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-oac</span> copy <span style="color: #660033;">-ovc</span> lavc \
<span style="color: #660033;">-lavcopts</span> <span style="color: #007800;">vcodec</span>=mpeg4:<span style="color: #007800;">vbitrate</span>=<span style="color: #000000;">2000</span>:vhq:<span style="color: #007800;">vpass</span>=<span style="color: #000000;">1</span> \
<span style="color: #660033;">-ffourcc</span> XVID <span style="color: #007800;">$SRC</span> <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">||</span> err_exit <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> \
<span style="color: #666666; font-style: italic;"># video pass 2</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started vpass2&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-sws</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-oac</span> copy <span style="color: #660033;">-ovc</span> lavc \
<span style="color: #660033;">-lavcopts</span> <span style="color: #007800;">vcodec</span>=mpeg4:<span style="color: #007800;">vbitrate</span>=<span style="color: #000000;">2000</span>:vhq:<span style="color: #007800;">vpass</span>=<span style="color: #000000;">2</span> \
<span style="color: #660033;">-ffourcc</span> XVID <span style="color: #007800;">$SRC</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;$2.longest.track.avi&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># log more stuff</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(date +%H:%M:%S)</span> done&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Longest track is <span style="color: #007800;">$title</span>&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Longest chapter is <span style="color: #007800;">$chapter</span>&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>########## lsdvd output ##########&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(lsdvd -x $1)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-the-longest-one-into-avi-using-mencoder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SMTP test message via shell script using netcat instead of telnet</title>
		<link>http://giantdorks.org/alain/smtp-test-message-via-shell-script-using-netcat-instead-of-telnet/</link>
		<comments>http://giantdorks.org/alain/smtp-test-message-via-shell-script-using-netcat-instead-of-telnet/#comments</comments>
		<pubDate>Fri, 14 May 2010 17:29:16 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=616</guid>
		<description><![CDATA[I&#8217;ve always used telnet for SMTP testing. Finally, got sick of copy/pasting and decided to write a quick script. But scripting telnet is a pain. Netcat to the rescue!
Call the script with the following arguments:

$ ./smtp.netcat.test mx.example.com 25 from@example.com to@example.com

And here&#8217;s the script:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# script to send test mail with netcat. 
# expects the following arguments:
# [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always used telnet for SMTP testing. Finally, got sick of copy/pasting and decided to write a quick script. But scripting telnet is a pain. Netcat to the rescue!</p>
<p>Call the script with the following arguments:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>smtp.netcat.test mx.example.com <span style="color: #000000;">25</span> from<span style="color: #000000; font-weight: bold;">@</span>example.com to<span style="color: #000000; font-weight: bold;">@</span>example.com</pre></div></div>

<p>And here&#8217;s the script:</p>
<p><span id="more-616"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># script to send test mail with netcat. </span>
<span style="color: #666666; font-style: italic;"># expects the following arguments:</span>
<span style="color: #666666; font-style: italic;"># 1. recepient mail server</span>
<span style="color: #666666; font-style: italic;"># 2. port (typically 25 or 465)</span>
<span style="color: #666666; font-style: italic;"># 3. mail from (e.g. from@example.com)</span>
<span style="color: #666666; font-style: italic;"># 4. mail to (e.g. to@example.com)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># for mail_input function</span>
<span style="color: #007800;">from</span>=$<span style="color: #000000;">3</span>
<span style="color: #007800;">to</span>=$<span style="color: #000000;">4</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># error handling</span>
<span style="color: #000000; font-weight: bold;">function</span> err_exit <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check if proper arguments are supplied</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">4</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Usage error!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; This script requires four arguments:&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; 1. recepient mail server&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; 2. port (typically 25 or 465)&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; 3. mail from (e.g. from@example.com)&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; 4. mail to (e.g. to@example.com)&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create message</span>
<span style="color: #000000; font-weight: bold;">function</span> mail_input <span style="color: #7a0874; font-weight: bold;">&#123;</span> 
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ehlo <span style="color: #007800;">$(hostname -f)</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;MAIL FROM: &lt;<span style="color: #007800;">$from</span>&gt;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;RCPT TO: &lt;<span style="color: #007800;">$to</span>&gt;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DATA&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;From: &lt;<span style="color: #007800;">$from</span>&gt;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;To: &lt;<span style="color: #007800;">$to</span>&gt;&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Subject: Testing one two three&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This is only a test. Please do not panic. If this works, then all is well, else all is not well.&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;In closing, Lorem ipsum dolor sit amet, consectetur adipiscing elit.&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;quit&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># test</span>
<span style="color: #666666; font-style: italic;">#mail_input</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># send</span>
mail_input <span style="color: #000000; font-weight: bold;">|</span> nc $<span style="color: #000000;">1</span> $<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/smtp-test-message-via-shell-script-using-netcat-instead-of-telnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Little script to identify child process</title>
		<link>http://giantdorks.org/alain/little-script-to-identify-child-process/</link>
		<comments>http://giantdorks.org/alain/little-script-to-identify-child-process/#comments</comments>
		<pubDate>Tue, 11 May 2010 17:29:50 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=608</guid>
		<description><![CDATA[I&#8217;ve got a script that loops through a list of directory names and compresses them. There are lots and once in a while I want to check on the progress and find out which directory in the list it&#8217;s working on.
The name of the script is compress.sh, tar will run as a child of it, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got a script that loops through a list of directory names and compresses them. There are lots and once in a while I want to check on the progress and find out which directory in the list it&#8217;s working on.</p>
<p>The name of the script is compress.sh, tar will run as a child of it, which I can locate using the parent PID:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">me<span style="color: #000000; font-weight: bold;">@</span>my:~$ show.proc.sh compress.sh
USER     TT         PID  PPID <span style="color: #000000; font-weight: bold;">%</span>CPU <span style="color: #000000; font-weight: bold;">%</span>MEM    VSZ  STARTED     TIME COMMAND
me       pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">19</span>    <span style="color: #000000;">1810</span> <span style="color: #000000;">24357</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.0</span>   <span style="color: #000000;">4496</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">15</span>:<span style="color: #000000;">37</span> 00:00:00  <span style="color: #000000; font-weight: bold;">|</span>           \_ <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> .<span style="color: #000000; font-weight: bold;">/</span>compress.sh
me       pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">19</span>    <span style="color: #000000;">1857</span>  <span style="color: #000000;">1810</span>  <span style="color: #000000;">0.5</span>  <span style="color: #000000;">0.0</span>   <span style="color: #000000;">3696</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">16</span>:03 00:00:01  <span style="color: #000000; font-weight: bold;">|</span>           <span style="color: #000000; font-weight: bold;">|</span>   \_ <span style="color: #c20cb9; font-weight: bold;">tar</span> cfj 833444.tar.bz2 <span style="color: #000000;">833444</span></pre></div></div>

<p>show.proc.sh:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># get pid</span>
<span style="color: #007800;">pid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>pgrep $<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ps</span> axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,<span style="color: #000000; font-weight: bold;">time</span>,args <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span>
<span style="color: #c20cb9; font-weight: bold;">ps</span> axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,<span style="color: #000000; font-weight: bold;">time</span>,args <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$pid</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span></pre></td></tr></table></div>

<p>compress.sh:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> d <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> dir.list.2010-05-<span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> cfj <span style="color: #007800;">$d</span>.tar.bz2 <span style="color: #007800;">$d</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$d</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/little-script-to-identify-child-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Varnish plugin error</title>
		<link>http://giantdorks.org/alain/wordpress-varnish-plugin-error/</link>
		<comments>http://giantdorks.org/alain/wordpress-varnish-plugin-error/#comments</comments>
		<pubDate>Tue, 11 May 2010 04:01:49 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=597</guid>
		<description><![CDATA[Was looking for a way to purge Varnish cache when pages are updated or added. WordPress Varnish plugin looks exactly like what I&#8217;m after, except it threw up some errors out of the box.

Errors:

Warning: fsockopen() expects parameter 2 to be long, string given in /path/to/wordpress-varnish/wp-varnish.php on line 138
()

and

Warning: fsockopen() expects parameter 2 to be long, [...]]]></description>
			<content:encoded><![CDATA[<p>Was looking for a way to purge Varnish cache when pages are updated or added. <a href="http://wordpress.org/extend/plugins/wordpress-varnish/">WordPress Varnish plugin</a> looks exactly like what I&#8217;m after, except it threw up some errors out of the box.</p>
<p><span id="more-597"></span></p>
<p>Errors:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Warning: fsockopen() expects parameter 2 to be long, string given in /path/to/wordpress-varnish/wp-varnish.php on line 138
()</pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Warning: fsockopen() expects parameter 2 to be long, string given in /path/to/wordpress-varnish/wp-varnish.php on line 115
()</pre></div></div>

<p>My hack to fix the errors and also to add MU blogs to list of common URLs to purge on changes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">-up</span> wp-varnish.php.default wp-varnish.php</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="diff" style="font-family:monospace;">--- wp-varnish.php.default	<span style="">2010</span>-05-<span style="">10</span> <span style="">17</span>:<span style="">20</span>:<span style="">25.000000000</span> -0700
<span style="color: #888822;">+++ wp-varnish.php	<span style="">2010</span>-05-<span style="">10</span> <span style="">21</span>:<span style="">10</span>:<span style="">05.000000000</span> -0700</span>
<span style="color: #440088;">@@ -<span style="">54</span>,<span style="">6</span> +<span style="">54</span>,<span style="">13</span> @@ class WPVarnish <span style="">&#123;</span></span>
     $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/&quot;<span style="">&#41;</span>;
     $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/feed/&quot;<span style="">&#41;</span>;
     $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/feed/atom/&quot;<span style="">&#41;</span>;
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/alain/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/alain/feed/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/alain/feed/atom/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/jason/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/jason/feed/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+    $this-&gt;WPVarnishPurgeObject<span style="">&#40;</span>&quot;/jason/feed/atom/&quot;<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+</span>
   <span style="">&#125;</span>
&nbsp;
   function WPVarnishAdminMenu<span style="">&#40;</span><span style="">&#41;</span> <span style="">&#123;</span>
<span style="color: #440088;">@@ -<span style="">112</span>,<span style="">7</span> +<span style="">119</span>,<span style="">7</span> @@ class WPVarnish <span style="">&#123;</span></span>
     $wpv_host = preg_replace<span style="">&#40;</span>$wpv_replace_wpurl, &quot;&quot;, $wpv_wpurl<span style="">&#41;</span>;
&nbsp;
     for <span style="">&#40;</span>$i = <span style="">0</span>; $i &lt; count <span style="">&#40;</span>$wpv_purgeaddr<span style="">&#41;</span>; $i++<span style="">&#41;</span> <span style="">&#123;</span>
<span style="color: #991111;">-      $varnish_sock = fsockopen<span style="">&#40;</span>$wpv_purgeaddr<span style="">&#91;</span>$i<span style="">&#93;</span>, $wpv_purgeport<span style="">&#91;</span>$i<span style="">&#93;</span>, $errno, $errstr, <span style="">30</span><span style="">&#41;</span>;</span>
<span style="color: #00b000;">+      $varnish_sock = fsockopen<span style="">&#40;</span>&quot;127.0.0.1&quot;, &quot;<span style="">80</span>&quot;, $errno, $errstr, <span style="">30</span><span style="">&#41;</span>;</span>
       if <span style="">&#40;</span>!$varnish_sock<span style="">&#41;</span> <span style="">&#123;</span>
         echo &quot;$errstr <span style="">&#40;</span>$errno<span style="">&#41;</span>&lt;br /&gt;\n&quot;;
       <span style="">&#125;</span> else <span style="">&#123;</span>
<span style="color: #440088;">@@ -<span style="">135</span>,<span style="">7</span> +<span style="">142</span>,<span style="">7</span> @@ class WPVarnish <span style="">&#123;</span></span>
     $wpv_host = preg_replace<span style="">&#40;</span>$wpv_replace_wpurl, &quot;&quot;, $wpv_wpurl<span style="">&#41;</span>;
&nbsp;
     for <span style="">&#40;</span>$i = <span style="">0</span>; $i &lt; count <span style="">&#40;</span>$wpv_purgeaddr<span style="">&#41;</span>; $i++<span style="">&#41;</span> <span style="">&#123;</span>
<span style="color: #991111;">-      $varnish_sock = fsockopen<span style="">&#40;</span>$wpv_purgeaddr<span style="">&#91;</span>$i<span style="">&#93;</span>, $wpv_purgeport<span style="">&#91;</span>$i<span style="">&#93;</span>, $errno, $errstr, <span style="">30</span><span style="">&#41;</span>;</span>
<span style="color: #00b000;">+      $varnish_sock = fsockopen<span style="">&#40;</span>&quot;127.0.0.1&quot;, &quot;<span style="">80</span>&quot;, $errno, $errstr, <span style="">30</span><span style="">&#41;</span>;</span>
       if <span style="">&#40;</span>!$varnish_sock<span style="">&#41;</span> <span style="">&#123;</span>
         echo &quot;$errstr <span style="">&#40;</span>$errno<span style="">&#41;</span>&lt;br /&gt;\n&quot;;
       <span style="">&#125;</span> else <span style="">&#123;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/wordpress-varnish-plugin-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploring methods to purge Varnish cache</title>
		<link>http://giantdorks.org/alain/exploring-methods-to-purge-varnish-cache/</link>
		<comments>http://giantdorks.org/alain/exploring-methods-to-purge-varnish-cache/#comments</comments>
		<pubDate>Tue, 11 May 2010 03:46:16 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=587</guid>
		<description><![CDATA[I&#8217;m considering implementing Varnish at Stanford Law and have been playing with it here to understand implications and workout issues. One issue is purging pages from cache as they are modified or new pages are added. Varnish provides several methods to do this (varnishadm, telnet and http).

1. Varnishadm
Purge a specific page (front page of this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m considering implementing Varnish at Stanford Law and have been playing with it here to understand implications and workout issues. One issue is purging pages from cache as they are modified or new pages are added. Varnish provides several methods to do this (varnishadm, telnet and http).</p>
<p><span id="more-587"></span></p>
<p>1. Varnishadm</p>
<p>Purge a specific page (front page of this blog, for example):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">varnishadm <span style="color: #660033;">-T</span> 127.0.0.1:<span style="color: #000000;">6082</span> purge req.url == <span style="color: #ff0000;">&quot;/alain/&quot;</span></pre></div></div>

<p>Result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">varnishadm <span style="color: #660033;">-T</span> 127.0.0.1:<span style="color: #000000;">6082</span> purge.list
    <span style="color: #000000;">0</span> 	req.url == <span style="color: #000000; font-weight: bold;">/</span>alain<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Purge any page matching a regular expression (front page of this blog, for example):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">varnishadm <span style="color: #660033;">-T</span> 127.0.0.1:<span style="color: #000000;">6082</span> purge.url <span style="color: #ff0000;">&quot;^/alain/$&quot;</span></pre></div></div>

<p>Result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">varnishadm <span style="color: #660033;">-T</span> 127.0.0.1:<span style="color: #000000;">6082</span> purge.list
    <span style="color: #000000;">0</span> 	req.url ~ ^<span style="color: #000000; font-weight: bold;">/</span>alain<span style="color: #000000; font-weight: bold;">/</span>$</pre></div></div>

<p>2. Telnet</p>
<p>Similar to running varnishadm, except we have to open a telnet connection first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">telnet localhost <span style="color: #000000;">6082</span>
purge req.url == <span style="color: #ff0000;">&quot;/alain/&quot;</span>
<span style="color: #000000;">200</span> <span style="color: #000000;">0</span></pre></div></div>

<p>My boxes don&#8217;t accept telnet connections from the Internets so I can&#8217;t think of a scenario where I&#8217;d be talking to varnishd via telnet, so varnishadm is what I&#8217;d use at the shell or in a script.</p>
<p>3. HTTP</p>
<p>This one is probably the one that will see the most use as it is most accessible for a web based application. The only caveat is that it doesn&#8217;t support regular expressions, so just one URL at a time can be passed this way.</p>
<p>Will test first via telnet:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Request:
telnet localhost 80
&nbsp;
Response:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
&nbsp;
Request:
PURGE /alain/ HTTP/1.0
Host: giantdorks.org
&nbsp;
Response:
HTTP/1.0 200 OK
Date: Tue, 11 May 2010 02:00:00 GMT
Server: Apache
X-Pingback: http://giantdorks.org/alain/xmlrpc.php
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=UTF-8
&nbsp;
...
Followed by the HTML output of the page</pre></div></div>

<p>Note that the HTTP request was &#8220;PURGE  HTTP/1.0&#8243; instead of the usual &#8220;GET  HTTP/1.1&#8243;.</p>
<p>Now on to a more useful example. Here&#8217;s a PHP example using the built in fsockopen function, example based on the one offered at <a href="http://php.net/manual/en/function.fsockopen.php">php.net</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;80&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$errstr</span> (<span style="color: #006699; font-weight: bold;">$errno</span>)&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PURGE /alain HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Host: giantdorks.org<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Connection: Close<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Here&#8217;s another one. Presents user with a form to supply the URL and host (virtual host). Slightly modified example pulled from <a href="http://varnish-cache.org/wiki/webservice_purging">varnish-cache.org</a>:</p>
<p>index.html:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Purge Varnish cache<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
  body {
        font-size: 10px;
  }
  h1 {
        font-weight: bold;
        color: #000000;
        border-bottom: 1px solid #C6EC8C;
        margin-bottom: 2em;
  }
  label {
        font-size: 160%;
        float: left;
        text-align: right;
        margin-right: 0.5em;
        display: block
  }
  input[type=&quot;text&quot;] {
        width: 500px;
  }
  .submit input {
        margin-left: 0em;
        margin-bottom: 1em;
  }
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Makes Varnish purge the supplied URL from its cache<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vpurge.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>URL<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;url&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>HOST<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;host&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p>vpurge.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># get param
</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$port</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;80&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$verbose</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># inits
</span>  <span style="color: #000088;">$sock</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span><span style="color: #000088;">$port</span><span style="color: #339933;">,</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span><span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;connections failed <span style="color: #006699; font-weight: bold;">$errno</span> <span style="color: #006699; font-weight: bold;">$errstr</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No params&quot;</span><span style="color: #339933;">;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #990000;">stream_set_timeout</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$pcommand</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;purge&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;"># Send command
</span>  <span style="color: #000088;">$pcommand</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.hash <span style="color: #006699; font-weight: bold;">$url</span>#<span style="color: #006699; font-weight: bold;">$host</span>#&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  put <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pcommand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  put <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;quit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #990000;">fclose</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> readit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #000088;">$verbose</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$verbose</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockstr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;rcv: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sockstr</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$verbose</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$str</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> put<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$sock</span><span style="color: #339933;">,</span><span style="color: #000088;">$verbose</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fwrite</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$verbose</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;send: <span style="color: #006699; font-weight: bold;">$str</span> &lt;br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    readit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/exploring-methods-to-purge-varnish-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to enumerate titles and chapters of a dvd and rip each into a separate avi using mencoder</title>
		<link>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-each-into-a-separate-avi-using-mencoder/</link>
		<comments>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-each-into-a-separate-avi-using-mencoder/#comments</comments>
		<pubDate>Thu, 06 May 2010 19:55:47 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Awk]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sed]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[lsdvd]]></category>
		<category><![CDATA[mencoder]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=568</guid>
		<description><![CDATA[BASH script to enumerate titles and chapters of a dvd and rip each into a separate avi using mencoder. DVD device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/).
To rip just the longest title, try this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# script to enumerate titles and chapters of a dvd and rip each [...]]]></description>
			<content:encoded><![CDATA[<p>BASH script to enumerate titles and chapters of a dvd and rip each into a separate avi using mencoder. DVD device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/).</p>
<p>To rip just the longest title, try <a href="http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-the-longest-one-into-avi-using-mencoder/">this</a>.</p>
<p><span id="more-568"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># script to enumerate titles and chapters of a dvd and rip each into a separate xvid avi</span>
<span style="color: #666666; font-style: italic;"># dvd-device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/)</span>
<span style="color: #666666; font-style: italic;"># expects dvd as $1 and dvd name as $2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># error handling</span>
<span style="color: #000000; font-weight: bold;">function</span> err_exit <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Confirm two arguments were passed</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Usage error! Need two arguments.<span style="color: #000099; font-weight: bold;">\n</span> Example: $0 dvd-device My.DVD<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check if VIDEO_TS exists</span>
<span style="color: #007800;">ddir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$1/VIDEO_TS&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s_/\+_/_'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ddir</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Error!<span style="color: #000099; font-weight: bold;">\n</span> Can't find <span style="color: #007800;">$ddir</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">log</span>=<span style="color: #ff0000;">&quot;dvd2xvid-all.log&quot;</span>
<span style="color: #007800;">tmp</span>=<span style="color: #ff0000;">&quot;/tmp/dvd.title.chapter.list&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remove log if exists</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$log</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Removing existing <span style="color: #007800;">$log</span>..&quot;</span>
   <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># test lsdvd</span>
lsdvd <span style="color: #660033;">-x</span> $<span style="color: #000000;">1</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># create Title and Chapter list</span>
lsdvd <span style="color: #660033;">-x</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Title&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$tmp</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># log date</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(date)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #666666; font-style: italic;"># outer loop goes through titles</span>
<span style="color: #000000; font-weight: bold;">for</span> title <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$tmp</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">&quot;^Title: [0-9]{2}&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> 
  <span style="color: #007800;">chapters</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$tmp</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Title: <span style="color: #007800;">$title</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">&quot;Chapters: [0-9]{2}&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #666666; font-style: italic;"># inner loop goes through chapters for each title</span>
    <span style="color: #000000; font-weight: bold;">for</span> chapter <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> 01 <span style="color: #007800;">$chapters</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> 
      <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> divx2pass.log frameno.avi <span style="color: #000000; font-weight: bold;">||</span> err_exit 
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> Processing Title <span style="color: #007800;">$title</span>, Chapter <span style="color: #007800;">$chapter</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
      <span style="color: #666666; font-style: italic;"># real work happens here</span>
      <span style="color: #007800;">SRC</span>=<span style="color: #ff0000;">&quot;dvd://<span style="color: #007800;">$title</span> -chapter <span style="color: #007800;">$chapter</span> -dvd-device $1 -alang en&quot;</span>
      <span style="color: #666666; font-style: italic;"># audio pass</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started apass&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
      <span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-oac</span> mp3lame <span style="color: #660033;">-lameopts</span> <span style="color: #007800;">mode</span>=<span style="color: #000000;">2</span>:cbr:<span style="color: #007800;">br</span>=<span style="color: #000000;">96</span>:<span style="color: #007800;">vol</span>=<span style="color: #000000;">0</span> \
      <span style="color: #660033;">-ovc</span> frameno <span style="color: #660033;">-o</span> frameno.avi <span style="color: #007800;">$SRC</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> \
      <span style="color: #666666; font-style: italic;"># video pass 1</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started vpass1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
      <span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-sws</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-oac</span> copy <span style="color: #660033;">-ovc</span> lavc \
      <span style="color: #660033;">-lavcopts</span> <span style="color: #007800;">vcodec</span>=mpeg4:<span style="color: #007800;">vbitrate</span>=<span style="color: #000000;">2000</span>:vhq:<span style="color: #007800;">vpass</span>=<span style="color: #000000;">1</span> \
      <span style="color: #660033;">-ffourcc</span> XVID <span style="color: #007800;">$SRC</span> <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">||</span> err_exit <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> \
      <span style="color: #666666; font-style: italic;"># video pass 2</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$(date +%H:%M:%S)</span> started vpass2&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
      <span style="color: #c20cb9; font-weight: bold;">nice</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> mencoder <span style="color: #660033;">-sws</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-oac</span> copy <span style="color: #660033;">-ovc</span> lavc \
      <span style="color: #660033;">-lavcopts</span> <span style="color: #007800;">vcodec</span>=mpeg4:<span style="color: #007800;">vbitrate</span>=<span style="color: #000000;">2000</span>:vhq:<span style="color: #007800;">vpass</span>=<span style="color: #000000;">2</span> \
      <span style="color: #660033;">-ffourcc</span> XVID <span style="color: #007800;">$SRC</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;$2.Title<span style="color: #007800;">$title</span>.Chapter<span style="color: #007800;">$chapter</span>.avi&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
    <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># log more stuff</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(date +%H:%M:%S)</span> done&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>########## lsdvd output ##########&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(lsdvd -x $1)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$tmp</span> <span style="color: #000000; font-weight: bold;">||</span> err_exit</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-script-to-enumerate-titles-and-chapters-of-a-dvd-and-rip-each-into-a-separate-avi-using-mencoder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get counts of directory depth levels with find, awk, uniq and sort</title>
		<link>http://giantdorks.org/alain/get-counts-of-directory-depth-levels-with-find-awk-uniq-and-sort/</link>
		<comments>http://giantdorks.org/alain/get-counts-of-directory-depth-levels-with-find-awk-uniq-and-sort/#comments</comments>
		<pubDate>Thu, 06 May 2010 17:24:17 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Awk]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=560</guid>
		<description><![CDATA[Let&#8217;s say we&#8217;ve got a bunch of directories and we&#8217;d like to get counts of how many directories are how many levels deep. 
Our directory structure:

$ find . -type d
.
./test1
./test1/test1.1
./test2
./test2/test2.1
./test2/test2.1/test2.2
./test3
./test3/test3.1
./test3/test3.1/test3.2
./test3/test3.1/test3.2/test3.3

There are a number of ways to do this, but I found awk to be most elegant as I wanted to be able to substract an [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say we&#8217;ve got a bunch of directories and we&#8217;d like to get counts of how many directories are how many levels deep. </p>
<p>Our directory structure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d
.
.<span style="color: #000000; font-weight: bold;">/</span>test1
.<span style="color: #000000; font-weight: bold;">/</span>test1<span style="color: #000000; font-weight: bold;">/</span>test1.1
.<span style="color: #000000; font-weight: bold;">/</span>test2
.<span style="color: #000000; font-weight: bold;">/</span>test2<span style="color: #000000; font-weight: bold;">/</span>test2.1
.<span style="color: #000000; font-weight: bold;">/</span>test2<span style="color: #000000; font-weight: bold;">/</span>test2.1<span style="color: #000000; font-weight: bold;">/</span>test2.2
.<span style="color: #000000; font-weight: bold;">/</span>test3
.<span style="color: #000000; font-weight: bold;">/</span>test3<span style="color: #000000; font-weight: bold;">/</span>test3.1
.<span style="color: #000000; font-weight: bold;">/</span>test3<span style="color: #000000; font-weight: bold;">/</span>test3.1<span style="color: #000000; font-weight: bold;">/</span>test3.2
.<span style="color: #000000; font-weight: bold;">/</span>test3<span style="color: #000000; font-weight: bold;">/</span>test3.1<span style="color: #000000; font-weight: bold;">/</span>test3.2<span style="color: #000000; font-weight: bold;">/</span>test3.3</pre></div></div>

<p>There are a number of ways to do this, but I found awk to be most elegant as I wanted to be able to substract an arbitrary number from the result and awk can count and do arithmetic all by itself:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> f; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'/'</span> <span style="color: #ff0000;">'{print NF -1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> -nr; <span style="color: #000000; font-weight: bold;">done</span>
      <span style="color: #000000;">3</span> <span style="color: #000000;">2</span>
      <span style="color: #000000;">3</span> <span style="color: #000000;">1</span>
      <span style="color: #000000;">2</span> <span style="color: #000000;">3</span>
      <span style="color: #000000;">1</span> <span style="color: #000000;">4</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/get-counts-of-directory-depth-levels-with-find-awk-uniq-and-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error saving Nvidia X server settings on a clean install of Ubuntu 9.10 (Karmic)</title>
		<link>http://giantdorks.org/alain/error-saving-nvidia-x-server-settings-on-a-clean-install-of-ubuntu-9-10-karmic/</link>
		<comments>http://giantdorks.org/alain/error-saving-nvidia-x-server-settings-on-a-clean-install-of-ubuntu-9-10-karmic/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 21:40:41 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=555</guid>
		<description><![CDATA[After a clean install of Ubuntu Karmic (9.10), on a box with an Nvidia card (1), went into &#8220;System&#8221; &#62; &#8220;Administration&#8221; &#62; &#8220;NVIDIA X server settings&#8221; and changed configuration to TwinView (I&#8217;m using dual monitors), which worked, but saving the configuration returned:

Failed to parse existing X config file '/etc/X11/xorg.conf'

Nothing further found in the logs. The [...]]]></description>
			<content:encoded><![CDATA[<p>After a clean install of Ubuntu Karmic (9.10), on a box with an Nvidia card (1), went into &#8220;System&#8221; &gt; &#8220;Administration&#8221; &gt; &#8220;NVIDIA X server settings&#8221; and changed configuration to TwinView (I&#8217;m using dual monitors), which worked, but saving the configuration returned:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Failed to parse existing X config file '/etc/X11/xorg.conf'</pre></div></div>

<p>Nothing further found in the logs. The solution was two-fold.</p>
<p><span id="more-555"></span></p>
<p>Firstly, running Nvidia config from the shell instead of the Administration menu, dumped a useful error to the screen, when attempting to save settings in the GUI:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> nvidia-settings 
&nbsp;
VALIDATION ERROR:  Data incomplete <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>xorg.conf.
Undefined Device <span style="color: #ff0000;">&quot;(null)&quot;</span> referenced by Screen <span style="color: #ff0000;">&quot;Default Screen&quot;</span>.</pre></div></div>

<p>Secondly, now that I know that the problem is that nvidia-settings is upset with something in the existing config, one way to solve this is to just let nvidia-xconfig generate a new config.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>xorg.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>xorg.conf.bak
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> nvidia-xconfig
&nbsp;
WARNING: Unable to locate<span style="color: #000000; font-weight: bold;">/</span>open X configuration file.
New X configuration <span style="color: #c20cb9; font-weight: bold;">file</span> written to <span style="color: #ff0000;">'/etc/X11/xorg.conf'</span></pre></div></div>

<p>A diff of the new xorg.conf against the backed up version, shows a bunch of new stuff was added along with TwinView options. Looks good to me. Now I reboot to confirm the new xorg.conf settings produce the result. </p>
<p>Yay, problem solved, on with my day.</p>
<p>(1) Specific model is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">lspci</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> VGA
01:<span style="color: #000000;">00.0</span> VGA compatible controller: nVidia Corporation G84 <span style="color: #7a0874; font-weight: bold;">&#91;</span>GeForce <span style="color: #000000;">8600</span> GT<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">rev</span> a1<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/error-saving-nvidia-x-server-settings-on-a-clean-install-of-ubuntu-9-10-karmic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pick out a range of characters with non-greedy grep</title>
		<link>http://giantdorks.org/alain/pick-out-a-range-of-characters-with-non-greedy-grep/</link>
		<comments>http://giantdorks.org/alain/pick-out-a-range-of-characters-with-non-greedy-grep/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 21:53:30 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[grep]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=551</guid>
		<description><![CDATA[Let&#8217;s say you&#8217;ve got a string like:

$ string=&#34;abc.Cat.def.1.zip.hij.Cut.klm.1.zip.Cat.no.2.zippqrs&#34;

Out of this string, you want to pick out Cat*zip (Cat.def.1.zip and Cat.no.2.zip), &#8220;.*&#8221; works but is greedy so this grabs too much:

$ echo $string &#124; grep -Eo &#34;Cat.*zip&#34;
Cat.def.1.zip.hij.Cut.klm.1.zip.Cat.no.2.zip

This does what we want:

$ echo $string &#124; grep -Eo &#34;Ca[t][^t]*.zip&#34;
Cat.def.1.zip
Cat.no.2.zip

]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you&#8217;ve got a string like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">string</span>=<span style="color: #ff0000;">&quot;abc.Cat.def.1.zip.hij.Cut.klm.1.zip.Cat.no.2.zippqrs&quot;</span></pre></div></div>

<p>Out of this string, you want to pick out Cat*zip (Cat.def.1.zip and Cat.no.2.zip), &#8220;.*&#8221; works but is greedy so this grabs too much:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$string</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">&quot;Cat.*zip&quot;</span>
Cat.def.1.zip.hij.Cut.klm.1.zip.Cat.no.2.zip</pre></div></div>

<p>This does what we want:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$string</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">&quot;Ca[t][^t]*.zip&quot;</span>
Cat.def.1.zip
Cat.no.2.zip</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/pick-out-a-range-of-characters-with-non-greedy-grep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revert back to manual Boxee installs</title>
		<link>http://giantdorks.org/alain/revert-back-to-manual-boxee-installs/</link>
		<comments>http://giantdorks.org/alain/revert-back-to-manual-boxee-installs/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 03:57:00 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=543</guid>
		<description><![CDATA[Previously, I had setup an Ubuntu Karmic box to install Boxee from the apt.boxee.tv APT repository. Since this repository appears to be unmaintained, I&#8217;m now reverting back to manual Boxee installs until an updated repository becomes available.

The steps below probably don&#8217;t apply to you, UNLESS you made APT changes to pull in Boxee from the [...]]]></description>
			<content:encoded><![CDATA[<p>Previously, I had setup an Ubuntu Karmic box to install Boxee from the apt.boxee.tv APT repository. Since this repository appears to be unmaintained, I&#8217;m now reverting back to manual Boxee installs until an updated repository becomes available.</p>
<p><span id="more-543"></span></p>
<p>The steps below probably don&#8217;t apply to you, <strong>UNLESS</strong> you made APT changes to pull in Boxee from the apt.boxee.tv Intrepid repository as per my <a href="http://giantdorks.org/alain/install-boxee-with-apt-on-ubuntu-9-10-karmic/">previous post</a>.</p>
<p>BTW, the version I got installed is 0.9.20.10263, yet I don&#8217;t see it available from apt.boxee.tv anymore. I&#8217;m guessing they&#8217;ve pulled beta releases (0.9.2x) off since I&#8217;ve grabbed it previously, as I now only see alpha  releases (0.9.1x) listed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-cache</span> madison boxee
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.14.6992 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.14.6992 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.14.6795 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.14.6795 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.13.6684 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.13.6684 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.12.6570 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.12.6570 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.11.5777 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.11.5777 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.11.5777 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.7.4826 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.7.4826 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.7.4826 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.6.4578 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv intrepid<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.6.4578 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span> 0.9.6.4578 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv jaunty<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000;">0.9</span>-r3970 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000;">0.9</span>-r3927 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000;">0.9</span>-r2492 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages
     boxee <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000;">0.9</span>-r2365 <span style="color: #000000; font-weight: bold;">|</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.boxee.tv hardy<span style="color: #000000; font-weight: bold;">/</span>main Packages</pre></div></div>

<p>First, I&#8217;m choosing to completely purge the current version along with any dependencies it pulled in.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> purge boxee
Reading package lists... Done
Building dependency <span style="color: #c20cb9; font-weight: bold;">tree</span>
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following packages will be REMOVED:
  boxee<span style="color: #7a0874; font-weight: bold;">&#123;</span>p<span style="color: #7a0874; font-weight: bold;">&#125;</span> comerr-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libcurl4-openssl-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libfaad-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libidn11-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libkadm5srv6<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libkdb5-<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libkrb5-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libldap2-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libmysqlclient15off<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libsdl-gfx1.2-<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libssl-dev<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libtre4<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libxmlrpc-c3<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> libxmlrpc-core-c3<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span>
  python-sqlite<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> python2.4<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span> xsel<span style="color: #7a0874; font-weight: bold;">&#123;</span>u<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">0</span> packages upgraded, <span style="color: #000000;">0</span> newly installed, <span style="color: #000000;">18</span> to remove and <span style="color: #000000;">0</span> not upgraded.
Need to get 0B of archives. After unpacking 28.5MB will be freed.</pre></div></div>

<p>I don&#8217;t have any settings I need to keep, so I&#8217;m deleting them as well. This would give the new version a clean slate, which might be unnecessary, but can&#8217;t hurt either.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> ~<span style="color: #000000; font-weight: bold;">/</span>.boxee<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Remove customizations we had added to install Boxee from Intrepid repository (WARNING: I don&#8217;t need these anymore because I had just added them for Boxee, YMMV!)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>apt.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>preferences <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list.d<span style="color: #000000; font-weight: bold;">/</span>intrepid.list <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list.d<span style="color: #000000; font-weight: bold;">/</span>boxee.list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update</pre></div></div>

<p>Now on to the manual install of the latest version:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.boxee.tv<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>ubuntu <span style="color: #660033;">-O</span> boxee.latest.deb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gdebi boxee.latest.deb</pre></div></div>

<p>If all worked as it should, you should find shortcut to Boxee under &#8220;Applications&#8221; &gt; &#8220;Sound &amp; Video&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/revert-back-to-manual-boxee-installs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Another Spam free month with SpamAssassin and Postfix</title>
		<link>http://giantdorks.org/alain/another-spam-free-month-with-spamassassin-and-postfix/</link>
		<comments>http://giantdorks.org/alain/another-spam-free-month-with-spamassassin-and-postfix/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 19:45:17 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Spam]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=533</guid>
		<description><![CDATA[I haven&#8217;t been getting any SPAM lately, so I thought I&#8217;d turn on catch-all to see what happens. Accepting mail for invalid recepients (e.g. anything @mydomain) caused about twice as much SPAM to be attempted, but still nothing got through to my Inbox:

------------------------------------
Stats for Feb 2010
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
192	126	1951	0	0
--------------------------------------------------------------
2269		Total messages
2077		Total Spam (Caught + Missed + Rejected)
91.53%		Spam as % [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been getting any SPAM lately, so I thought I&#8217;d turn on catch-all to see what happens. Accepting mail for invalid recepients (e.g. anything @mydomain) caused about twice as much SPAM to be attempted, but still nothing got through to my Inbox:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">------------------------------------
Stats for Feb 2010
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
192	126	1951	0	0
--------------------------------------------------------------
2269		Total messages
2077		Total Spam (Caught + Missed + Rejected)
91.53%		Spam as % of all mail
93.93%		% of Spam rejected by Postfix at SMTP time
0%		False positive rate (Ham misclassified as Spam)
0%		False negative rate (Spam misclassified as Ham)
100.00%		Spam catch rate (Spam filter accuracy)
--------------------------------------------------------------</pre></div></div>

<p>As you can see, Postfix got most of it, then SpamAssasin got the rest. I heart Postfix and SpamAssassin. <img src='http://giantdorks.org/alain/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/another-spam-free-month-with-spamassassin-and-postfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix for broken Wi-Fi in Ubuntu 9.10 (Karmic) on a Dell laptop with Broadcom adapter</title>
		<link>http://giantdorks.org/alain/fix-for-broken-wi-fi-in-ubuntu-9-10-karmic-on-a-dell-laptop-with-broadcom-adapter/</link>
		<comments>http://giantdorks.org/alain/fix-for-broken-wi-fi-in-ubuntu-9-10-karmic-on-a-dell-laptop-with-broadcom-adapter/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 22:17:15 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Wireless]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=528</guid>
		<description><![CDATA[Did a fresh install of Ubuntu 9.10 (Karmic) on an old Inspiron E1505, only to find Wi-Fi not working. Fortunately the fix was easy.

Firstly, more on the problem. I was able to switch Bluetooth on/off with Fn+F2 keys, but the Wi-Fi icon remained dark. In the BIOS, both Bluetooth and Wireless were turned on and [...]]]></description>
			<content:encoded><![CDATA[<p>Did a fresh install of Ubuntu 9.10 (Karmic) on an old Inspiron E1505, only to find Wi-Fi not working. Fortunately the fix was easy.</p>
<p><span id="more-528"></span></p>
<p>Firstly, more on the problem. I was able to switch Bluetooth on/off with Fn+F2 keys, but the Wi-Fi icon remained dark. In the BIOS, both Bluetooth and Wireless were turned on and Fn+F2 was set to operate on both.</p>
<p>This laptop has the following adapter:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>lplx:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">lspci</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000;">802.11</span>
0b:<span style="color: #000000;">00.0</span> Network controller: Broadcom Corporation BCM4311 802.11b<span style="color: #000000; font-weight: bold;">/</span>g WLAN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">rev</span> 01<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The syslog had errors like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Feb 28 12:54:24 lplx kernel: [   24.670763] b43-phy0 ERROR: Firmware file &quot;b43/ucode5.fw&quot; not found
Feb 28 12:54:24 lplx kernel: [   24.670769] b43-phy0 ERROR: Firmware file &quot;b43-open/ucode5.fw&quot; not found
Feb 28 12:54:24 lplx kernel: [   24.670773] b43-phy0 ERROR: You must go to http://wireless.kernel.org/en/users/Drivers/b43#devicefirmware and download the correct firmware for this driver version. Please carefully read all instructions on this website.</pre></div></div>

<p>Since the error was about missing drivers and lspci told me I&#8217;m using the BCM4311 adapter, first thing I tried was search APT descriptions for it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>lplx:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> search ~dBCM4311
p   bcmwl-kernel-source                   - Broadcom <span style="color: #000000;">802.11</span> Linux STA wireless driver <span style="color: #7a0874; font-weight: bold;">source</span>
&nbsp;
ak<span style="color: #000000; font-weight: bold;">@</span>lplx:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> show bcmwl-kernel-source
Package: bcmwl-kernel-source
New: <span style="color: #c20cb9; font-weight: bold;">yes</span>
State: not installed
Automatically installed: no
Version: 5.10.91.9+bdcom-0ubuntu4
Priority: optional
Section: restricted<span style="color: #000000; font-weight: bold;">/</span>admin
Maintainer: Ubuntu Core Developers 
Uncompressed Size: <span style="color: #000000;">1</span>,835k
Depends: dkms, linux-libc-dev, libc6-dev, linux-headers-generic
Description: Broadcom <span style="color: #000000;">802.11</span> Linux STA wireless driver <span style="color: #7a0874; font-weight: bold;">source</span>
 These package contains Broadcom <span style="color: #000000;">802.11</span> Linux STA wireless driver <span style="color: #000000; font-weight: bold;">for</span> use with Broadcom<span style="color: #ff0000;">'s BCM4311-, BCM4312-, BCM4321-, and BCM4322-based hardware.</span></pre></div></div>

<p>Hmm, sounds promising, let&#8217;s try it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>lplx:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> bcmwl-kernel-source</pre></div></div>

<p>After a reboot, the Wi-Fi icon on the keyboard lit up and Network Manager saw my wireless network. Sweet.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/fix-for-broken-wi-fi-in-ubuntu-9-10-karmic-on-a-dell-laptop-with-broadcom-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>davfs2 on Karmic claims non existent files exist</title>
		<link>http://giantdorks.org/alain/davfs2-on-karmic-claims-non-existent-files-exist/</link>
		<comments>http://giantdorks.org/alain/davfs2-on-karmic-claims-non-existent-files-exist/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 07:28:18 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=522</guid>
		<description><![CDATA[Following a recent update, started getting errors copying files to a WebDAV mount point:

cp: cannot create regular file `./todo': File exists


And when creating a new file:

touch: cannot touch `alain.test': File exists

The error in the Apache log was:

[Thu Feb 25 22:52:42 2010] [error] [client xx.xx.xx.xx] Could not LOCK /path/to/alain.test due to a failed precondition (e.g. other [...]]]></description>
			<content:encoded><![CDATA[<p>Following a recent update, started getting errors copying files to a WebDAV mount point:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cp: cannot create regular file `./todo': File exists</pre></div></div>

<p><span id="more-522"></span></p>
<p>And when creating a new file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">touch: cannot touch `alain.test': File exists</pre></div></div>

<p>The error in the Apache log was:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[Thu Feb 25 22:52:42 2010] [error] [client xx.xx.xx.xx] Could not LOCK /path/to/alain.test due to a failed precondition (e.g. other locks).  [412, #0]</pre></div></div>

<p>This is happening in Karmic with davfs2 1.4.1-1, but not in Intrepid with davfs2 1.3.3-1.</p>
<p>For now, running this on the client resolves the error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;if_match_bug 1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>davfs2<span style="color: #000000; font-weight: bold;">/</span>davfs2.conf</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/davfs2-on-karmic-claims-non-existent-files-exist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple isolated instances of Firefox within a single login session on Linux</title>
		<link>http://giantdorks.org/alain/multiple-isolated-instances-of-firefox-within-a-single-login-session-on-linux/</link>
		<comments>http://giantdorks.org/alain/multiple-isolated-instances-of-firefox-within-a-single-login-session-on-linux/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:27:52 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=513</guid>
		<description><![CDATA[Here&#8217;s a simple solution to run multiple instances of Firefox, each with own user profile (and thus cookies, extensions and themes), all running as separate processes. Useful for troubleshooting and to keep one misbehaving site from crashing all your firefox windows (I&#8217;m guilty of running way too many at once).

I used to accomplish this by [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple solution to run multiple instances of Firefox, each with own user profile (and thus cookies, extensions and themes), all running as separate processes. Useful for troubleshooting and to keep one misbehaving site from crashing all your firefox windows (I&#8217;m guilty of running way too many at once).</p>
<p><span id="more-513"></span></p>
<p>I used to accomplish this by setting up multiple user accounts and then using sux to startup multiple instances:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">user1<span style="color: #000000; font-weight: bold;">@</span>madcow:<span style="color: #000000; font-weight: bold;">/</span>$ sux user2
user2<span style="color: #000000; font-weight: bold;">@</span>madcow:<span style="color: #000000; font-weight: bold;">/</span>$ firefox <span style="color: #000000; font-weight: bold;">&amp;</span></pre></td></tr></table></div>

<p>The above will fire up a firefox instance inside the user1&#8217;s desktop session running as user2. It works and maybe preferable in some situations, but there&#8217;s a better way for what I&#8217;m trying to do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">user1<span style="color: #000000; font-weight: bold;">@</span>madcow:<span style="color: #000000; font-weight: bold;">/</span>$ firefox <span style="color: #660033;">-ProfileManager</span> <span style="color: #660033;">-no-remote</span> <span style="color: #000000; font-weight: bold;">&amp;</span></pre></td></tr></table></div>

<p>The above will fire up the Profile Manager window allowing to start up separate instances of Firefox with multiple profiles:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">user1<span style="color: #000000; font-weight: bold;">@</span>madcow:<span style="color: #000000; font-weight: bold;">/</span>$ <span style="color: #c20cb9; font-weight: bold;">ps</span> auxf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> auxf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> firefox
USER       PID <span style="color: #000000; font-weight: bold;">%</span>CPU <span style="color: #000000; font-weight: bold;">%</span>MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
user1    <span style="color: #000000;">21652</span>  <span style="color: #000000;">2.8</span>  <span style="color: #000000;">7.5</span> <span style="color: #000000;">460416</span> <span style="color: #000000;">274592</span> ?       Sl   Feb10  <span style="color: #000000;">23</span>:05 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>firefox-3.0.17<span style="color: #000000; font-weight: bold;">/</span>firefox <span style="color: #660033;">-p</span> <span style="color: #660033;">-no-remote</span>
user1    <span style="color: #000000;">22432</span>  <span style="color: #000000;">1.7</span>  <span style="color: #000000;">1.9</span> <span style="color: #000000;">225680</span> <span style="color: #000000;">69688</span> ?        Sl   Feb10   <span style="color: #000000;">1</span>:05 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>firefox-3.0.17<span style="color: #000000; font-weight: bold;">/</span>firefox <span style="color: #660033;">-p</span> <span style="color: #660033;">-no-remote</span>
user1    <span style="color: #000000;">23004</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.7</span>  <span style="color: #000000;">73964</span> <span style="color: #000000;">28296</span> ?        Sl   Feb10   <span style="color: #000000;">0</span>:01 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>firefox-3.0.17<span style="color: #000000; font-weight: bold;">/</span>firefox <span style="color: #660033;">-p</span> <span style="color: #660033;">-no-remote</span></pre></td></tr></table></div>

<p>To make this the default way of starting up Firefox in Gnome, right click the Firefox application launcher in the panel, go to &#8220;Properties&#8221; and change &#8220;Command&#8221; to &#8220;firefox -ProfileManager -no-remote&#8221;.</p>
<p>Very ni-i-ice.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/multiple-isolated-instances-of-firefox-within-a-single-login-session-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to verify tar archives</title>
		<link>http://giantdorks.org/alain/shell-script-to-verify-tar-archives/</link>
		<comments>http://giantdorks.org/alain/shell-script-to-verify-tar-archives/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:39:31 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=509</guid>
		<description><![CDATA[Got thousands of tar archives being transferred from various machines to one repository. Found that some of the archives are bad, either because the network transfer didn&#8217;t complete or the archive process was interrupted on the machine that created the archive (due to insufficient disk space, etc). Whatever the cause, needed a method to verify [...]]]></description>
			<content:encoded><![CDATA[<p>Got thousands of tar archives being transferred from various machines to one repository. Found that some of the archives are bad, either because the network transfer didn&#8217;t complete or the archive process was interrupted on the machine that created the archive (due to insufficient disk space, etc). Whatever the cause, needed a method to verify the archive integrity.</p>
<p>Tar provides options for verify the archive integrity by comparing it with the file system. In this case, I needed the ability to verify the archive without access to the original file system.</p>
<p>The BASH one liner below will find all archives below current directory, loop through each one attempting to list its contents, discard the archive content list, capture and log the tar command&#8217;s exit status along with archive name and redirect both to a log. Exit status of 0 means the archive is good, 2 means it&#8217;s bad (haven&#8217;t seen a 1). Redirecting output to /dev/null while capturing exit status turned out trickier than I thought, but this seems to work well:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*tar.bz2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> tfj <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #007800;">err</span>=<span style="color: #ff0000;">&quot;$?&quot;</span>; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$err</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> tar-check.list; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p><span id="more-509"></span></p>
<p>Output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> tar-check.list
<span style="color: #000000;">2</span> .<span style="color: #000000; font-weight: bold;">/</span>755806.tar.bz2
<span style="color: #000000;">2</span> .<span style="color: #000000; font-weight: bold;">/</span>708955.tar.bz2
<span style="color: #000000;">0</span> .<span style="color: #000000; font-weight: bold;">/</span>313854.tar.bz2
<span style="color: #000000;">0</span> .<span style="color: #000000; font-weight: bold;">/</span>313857.tar.bz2</pre></td></tr></table></div>

<p>BTW, the specific error I&#8217;ve gotten, which the above method will identify, is:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Inappropriate ioctl for device
        Input file = (stdin), output file = (stdout)
&nbsp;
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
&nbsp;
You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.
&nbsp;
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-script-to-verify-tar-archives/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculate split percentage as part of the split command line</title>
		<link>http://giantdorks.org/alain/calculate-split-percentage-as-part-of-the-split-command-line/</link>
		<comments>http://giantdorks.org/alain/calculate-split-percentage-as-part-of-the-split-command-line/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 20:02:23 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=497</guid>
		<description><![CDATA[The split command is one gem of a Giant Dork tool, but it expects to be given the number of lines to split a file along. It&#8217;s easy enough to fire up a calculator to do this, but sometimes a programmatic method is desirable. Here&#8217;s a bashism that&#8217;ll do it:

1
split -l $&#40;echo $&#40;&#40; $&#40;cat sourcefile [...]]]></description>
			<content:encoded><![CDATA[<p>The split command is one gem of a Giant Dork tool, but it expects to be given the number of lines to split a file along. It&#8217;s easy enough to fire up a calculator to do this, but sometimes a programmatic method is desirable. Here&#8217;s a bashism that&#8217;ll do it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">split</span> <span style="color: #660033;">-l</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> sourcefile <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> sourcefile sourcefile.</pre></td></tr></table></div>

<p><span id="more-497"></span></p>
<p>Assuming a file called sourcefile has 270 lines in it, the above will produce three smaller files of 90 lines each:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>pork:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> sourcefile.<span style="color: #000000; font-weight: bold;">*</span>
  <span style="color: #000000;">90</span> sourcefile.aa
  <span style="color: #000000;">90</span> sourcefile.ab
  <span style="color: #000000;">90</span> sourcefile.ac
 <span style="color: #000000;">270</span> total</pre></td></tr></table></div>

<p>If the number of lines doesn&#8217;t devide up neatly (let&#8217;s say sourcefile contains 271 lines), split will produce an extra file with the difference:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>pork:~$ <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> sourcefile.<span style="color: #000000; font-weight: bold;">*</span>
  <span style="color: #000000;">90</span> sourcefile.aa
  <span style="color: #000000;">90</span> sourcefile.ab
  <span style="color: #000000;">90</span> sourcefile.ac
   <span style="color: #000000;">1</span> sourcefile.ad
 <span style="color: #000000;">271</span> total</pre></td></tr></table></div>

<p>I&#8217;m personally partial to numeric suffixes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ak<span style="color: #000000; font-weight: bold;">@</span>pork:~$ <span style="color: #c20cb9; font-weight: bold;">split</span> <span style="color: #660033;">-l</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> sourcefile <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-da3</span> sourcefile sourcefile.
ak<span style="color: #000000; font-weight: bold;">@</span>pork:~$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-1</span>
sourcefile
sourcefile.000
sourcefile.001
sourcefile.002
sourcefile.003</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/calculate-split-percentage-as-part-of-the-split-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FTP server with virtual users on Debian Lenny</title>
		<link>http://giantdorks.org/alain/ftp-server-with-virtual-users-on-debian-lenny/</link>
		<comments>http://giantdorks.org/alain/ftp-server-with-virtual-users-on-debian-lenny/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 05:17:39 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[FTP]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=495</guid>
		<description><![CDATA[Had to setup an FTP server at work (yuck), guides I found elsewhere didn&#8217;t do exactly what I was after, so it took some trial and error to achieve the setup I needed.

Objectives:

Be able to create multiple virtual users without having to create a shell account for every FTP user
Individually set permissions for each FTP [...]]]></description>
			<content:encoded><![CDATA[<p>Had to setup an FTP server at work (yuck), guides I found elsewhere didn&#8217;t do exactly what I was after, so it took some trial and error to achieve the setup I needed.</p>
<p><span id="more-495"></span></p>
<p>Objectives:</p>
<ul>
<li>Be able to create multiple virtual users without having to create a shell account for every FTP user</li>
<li>Individually set permissions for each FTP user</li>
<li>FTP users should by default be locked inside a chroot</li>
<li>However, need to be able to provide read/write access outside the chroot on exception basis</li>
</ul>
<p>I used Proftpd on Debian Lenny to achieve the above.</p>
<p><strong><em>Note:</em></strong> ip_conntrack_ftp kernel module is not loaded by default on Debian Lenny. Without it, everything will seem to work, except FTP LIST command will return &#8220;Connection timed out&#8221; and &#8220;Failed to retrieve directory listing&#8221; errors.</p>
<p>To resolve, load the module:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> modprobe ip_conntrack_ftp</pre></td></tr></table></div>

<p>To ensure it gets loaded on reboot, do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #7a0874; font-weight: bold;">echo</span> ip_conntrack_ftp <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>modules</pre></td></tr></table></div>

<p>1. Install proftpd</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> proftpd</pre></td></tr></table></div>

<p>2. Create home directories for the virtual ftp users (we&#8217;re just creating two for this example):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">read</span>,<span style="color: #c20cb9; font-weight: bold;">write</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> proftpd:nogroup <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span></pre></td></tr></table></div>

<p>3. Get the uid and gid of the proftpd user (profptd install script should have created it):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
proftpd:x:<span style="color: #000000;">109</span>:<span style="color: #000000;">65534</span>::<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>proftpd:<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span></pre></td></tr></table></div>

<p>4. Create virtual ftp users</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> ftpasswd <span style="color: #660033;">--passwd</span> <span style="color: #660033;">--name</span>=user1 <span style="color: #660033;">--uid</span>=<span style="color: #000000;">109</span> <span style="color: #660033;">--gid</span>=<span style="color: #000000;">65534</span> <span style="color: #660033;">--home</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>user1 <span style="color: #660033;">--shell</span>=<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--file</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>proftpd<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> ftpasswd <span style="color: #660033;">--passwd</span> <span style="color: #660033;">--name</span>=user2 <span style="color: #660033;">--uid</span>=<span style="color: #000000;">109</span> <span style="color: #660033;">--gid</span>=<span style="color: #000000;">65534</span> <span style="color: #660033;">--home</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>user2 <span style="color: #660033;">--shell</span>=<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--file</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>proftpd<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p><em><strong>Note:</strong></em> to change the password for the virtual FTP user, do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> ftpasswd <span style="color: #660033;">--change-password</span> <span style="color: #660033;">--passwd</span> <span style="color: #660033;">--name</span>=user1 <span style="color: #660033;">--file</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>proftpd<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p>5. Add some directives to proftpd config file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AuthUserFile</span>            /etc/proftpd/passwd
DefaultRoot             ~
RequireValidShell       <span style="color: #0000ff;">off</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># VALID LOGINS</span>
&lt;Limit LOGIN&gt;
   AllowUser user1
   AllowUser user2
   DenyALL
&lt;/Limit&gt;
&nbsp;
<span style="color: #adadad; font-style: italic;"># USER 1</span>
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /var/ftp/user1/read&gt;
    &lt;Limit ALL&gt;
        DenyAll
    &lt;/Limit&gt;
    &lt;Limit DIRS READ&gt;
        AllowUser user1
    &lt;/Limit&gt;
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /var/ftp/user1/write&gt;
    &lt;Limit ALL&gt;
        DenyAll
    &lt;/Limit&gt;
    &lt;Limit DIRS READ WRITE&gt;
        AllowUser user1
    &lt;/Limit&gt;
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&nbsp;
<span style="color: #adadad; font-style: italic;"># USER 2</span>
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /var/ftp/user2/read&gt;
    &lt;Limit ALL&gt;
        DenyAll
    &lt;/Limit&gt;
    &lt;Limit DIRS READ&gt;
        AllowUser user2
    &lt;/Limit&gt;
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /var/ftp/user2/write&gt;
    &lt;Limit ALL&gt;
        DenyAll
    &lt;/Limit&gt;
    &lt;Limit DIRS READ WRITE&gt;
        AllowUser user2
    &lt;/Limit&gt;
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;</pre></td></tr></table></div>

<p>6. If you use a firewall, don&#8217;t forget to open up port 21. If you can get away with it, it&#8217;s of course best to open it up to a narrowly defined set of IPs.</p>
<p>7. Restart proftpd and you should be able to connect with an FTP client using the credentials for users we setup.</p>
<p>8. For read only file system access outside of the chroot:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>read<span style="color: #000000; font-weight: bold;">/</span>blah
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">--bind</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>somewhere<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>read<span style="color: #000000; font-weight: bold;">/</span>blah<span style="color: #000000; font-weight: bold;">/</span></pre></td></tr></table></div>

<p>Useful links:</p>
<ol>
<li><a href="http://www.castaglia.org/proftpd/doc/contrib/ProFTPD-mini-HOWTO-Limit.html">ProFTPD-mini-HOWTO-Limit</a></li>
<li><a href="http://www.castaglia.org/proftpd/doc/contrib/ProFTPD-mini-HOWTO-VirtualUsers.html">ProFTPD-mini-HOWTO-VirtualUsers</a></li>
<li><a href="http://www.castaglia.org/proftpd/doc/contrib/ProFTPD-mini-HOWTO-AuthFiles.html">ProFTPD-mini-HOWTO-AuthFiles</a></li>
<li><a href="http://www.castaglia.org/proftpd/contrib/ftpasswd.html">ProFTPD ftpasswd</a></li>
<li><a href="http://www.castaglia.org/proftpd/doc/contrib/ProFTPD-mini-HOWTO-Chroot.html">ProFTPD-mini-HOWTO-Chroot</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/ftp-server-with-virtual-users-on-debian-lenny/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excellent free SSL certificates with killer service to boot</title>
		<link>http://giantdorks.org/alain/excellent-free-ssl-certificates-with-killer-service-to-boot/</link>
		<comments>http://giantdorks.org/alain/excellent-free-ssl-certificates-with-killer-service-to-boot/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 04:37:56 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=460</guid>
		<description><![CDATA[If you aren&#8217;t using StartSSL for your SSL certificate needs, you should take a hard look in the mirror and ask if the outrageous prices aged established Certificate Authorities charge are still justified. After all, it&#8217;s the same encryption &#8212; what you&#8217;re paying for is browser support. Well, from the consumer perspective, rigor of the [...]]]></description>
			<content:encoded><![CDATA[<p>If you aren&#8217;t using StartSSL for your SSL certificate needs, you should take a hard look in the mirror and ask if the outrageous prices <strike>aged</strike> established Certificate Authorities charge are still justified. After all, it&#8217;s the same encryption &#8212; what you&#8217;re paying for is browser support. Well, from the consumer perspective, rigor of the validation process is even more important &#8212; ironically, I found StartCom validation process for their $40 Class 2 certificates to be far more rigorous than the &#8220;established&#8221; players who charge twenty times that.</p>
<p>When I first took a StartCom cert for a spin a couple of years ago, the issue I had was spotty browser support. Today, I&#8217;m happy to report that web browser support for the free StartSSL certificate is excellent. Well, almost&#8230;</p>
<p><span id="more-460"></span></p>
<p>Firstly, I&#8217;d like to say that both pre-sales and post-sales support are unbelievably good. Terms &#8220;pre-sales&#8221; and &#8220;post-sales&#8221; here used loosely &#8212; the cert I got for giantdorks.org is free, after all. Anyway, I got almost instant email responses that actually made sense from people that run the thing, not some nonsense first level support crap you&#8217;d normally expect in the rare instances you do hear back.</p>
<p>Secondly, the setup is very fast. I was installing the certs about an hour after signing up. I haven&#8217;t been buying a lot of certs lately, but the last one I purchased was a $15 RapidSSL cert from Dynadot and while they were great, it took about a day to get the certificate (and that was actually a renewal).</p>
<p>Finally, StartSSL browser support seems great. All browsers I care about had no problems with the free StartSSL cert. I tested the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">Linux ..... Galeon 2.0.6 
Linux ..... Epiphany 2.24.1
Linux ..... Firefox 3.0.15
Linux ..... Firefox 3.5.9
iPhone .... Safari
iPhone .... Mercury 2.1
Windows ... IE 7
Windows ... IE 8
Windows ... Safari 3.1.2
Windows ... Firefox 3.1</pre></td></tr></table></div>

<p>If you use other browsers on other platforms, please point them to <a href="https://www.startssl.com/">https://www.startssl.com/</a> and feel free to comment below if your browser craps on itself &#8212; I&#8217;d love to hear about any browsers that don&#8217;t like the StartSSL certificate.</p>
<p>The only browser that complained about the free StartSSL cert was IE6 on Win2K. I personally don&#8217;t care &#8212; anyone still using IE6 should get off the Web immediately. If you know anyone still running Win2K, plead they switch to Firefox or Chrome &#8212; IE6 sucks ass &#8212; if they refuse, unplug their monitor, which should bewilder them (and the <a href="http://www.my3cents.com/productReview.cgi?company=Geek+Squad">Meek Squad</a>) for months. However, If you do need a SSL cert supported by Internet Explorer 6, but don&#8217;t need the green address bar (and don&#8217;t enjoy flushing money down the drain), try the $15 RapidSSL cert from Dynadot. I can confirm that IE6 is happy with it.</p>
<p>Other than that, I don&#8217;t see any reason to not go to StartCom for all my SSL certificate needs. If you do, I&#8217;d like to hear about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/excellent-free-ssl-certificates-with-killer-service-to-boot/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Install Boxee with APT on Ubuntu 9.10 (Karmic)</title>
		<link>http://giantdorks.org/alain/install-boxee-with-apt-on-ubuntu-9-10-karmic/</link>
		<comments>http://giantdorks.org/alain/install-boxee-with-apt-on-ubuntu-9-10-karmic/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:26:31 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[APT]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=452</guid>
		<description><![CDATA[Boxee folks helpfully host an APT repository (http://apt.boxee.tv/), but, as of this writing, only for Ubuntu 8.04 (Hardy) and 8.10 (Intrepid). But if you happen to run a later version such as 9.04 (Jaunty) or 9.10 (Karmic), you could still install from the Boxee repository through the magic of APT pinning. This method should work [...]]]></description>
			<content:encoded><![CDATA[<p>Boxee folks helpfully host an APT repository (http://apt.boxee.tv/), but, as of this writing, only for Ubuntu 8.04 (Hardy) and 8.10 (Intrepid). But if you happen to run a later version such as 9.04 (Jaunty) or 9.10 (Karmic), you could still install from the Boxee repository through the magic of APT pinning. This method should work just as well with later versions of Ubuntu also.</p>
<p><span id="more-452"></span></p>
<blockquote><p><strong><span style="color: #ff0000"><span style="text-decoration: underline">Update 5 March 2010</span></span>: Since APT repository at apt.boxee.tv appears to be unmaintained, I&#8217;ve reverted back to manual installs until an updated repository becomes available. I don&#8217;t recommend you follow the steps below unless you want to get stuck with an outdated Boxee version. Here are <a href="http://giantdorks.org/alain/revert-back-to-manual-boxee-installs/">the steps to revert back</a>.</strong></p></blockquote>
<p>First we make sure the system is up to date:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> safe-upgrade</pre></div></div>

<blockquote><p>Note: If you&#8217;re running Jaunty, substitute references to &#8220;karmic&#8221; with &#8220;jaunty&#8221;.</p></blockquote>
<p>Create &#8220;/etc/apt/apt.conf&#8221; to tell APT that Karmic is our default release:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">APT::Default-Release &quot;karmic&quot;;</pre></div></div>

<p>Create &#8220;/etc/apt/preferences&#8221; to give Karmic packages a higher priority than Intrepid packages:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Package: *
Pin: release a=karmic
Pin-Priority: 990
&nbsp;
Package: *
Pin: release a=intrepid
Pin-Priority: 450</pre></div></div>

<p>Create &#8220;/etc/apt/sources.list.d/intrepid.list&#8221; to tell APT where to get Intrepid packages:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">deb http://us.archive.ubuntu.com/ubuntu/ intrepid main restricted universe multiverse</pre></div></div>

<p>Create &#8220;/etc/apt/sources.list.d/boxee.list&#8221; to give APT a source for Boxee packages:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">deb http://apt.boxee.tv intrepid main</pre></div></div>

<p>Now we update APT to pick up our changes and install Boxee:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> boxee</pre></div></div>

<p>If all worked as it should, you should find shortcut to Boxee under &#8220;Applications&#8221; &gt; &#8220;Sound &amp; Video&#8221;. Now, as new versions of Boxee are made available through their APT repo, we can get them through Synaptic APT GUI or via the console by running &#8220;sudo aptitude update &amp;&amp; sudo aptitude safe-upgrade&#8221;.</p>
<p>Once Boxee adds Karmic support to their repo, we can remove the Intrepid Ubuntu sources and replace references to Intrepid with Karmic so APT will continue to get Boxee packages from the Boxee repo, just get Boxee packages for Karmic instead of Intrepid:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>apt.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>preferences <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list.d<span style="color: #000000; font-weight: bold;">/</span>intrepid.list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'s/intrepid/karmic/'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list.d<span style="color: #000000; font-weight: bold;">/</span>boxee.list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update</pre></div></div>

<p>Once Boxee packages become available from Ubuntu sources, we can remove the Boxee repo altogether:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list.d<span style="color: #000000; font-weight: bold;">/</span>boxee.list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> update</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/install-boxee-with-apt-on-ubuntu-9-10-karmic/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CentOS vnstat error: Unable to create database backup</title>
		<link>http://giantdorks.org/alain/centos-vnstat-error-unable-create-database-backup/</link>
		<comments>http://giantdorks.org/alain/centos-vnstat-error-unable-create-database-backup/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 08:18:48 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[CentOS]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=444</guid>
		<description><![CDATA[On CentOS 5.4, the vnstat cron job generates an error:

Error: Unable create database backup &#34;/var/lib/vnstat/.venet0&#34;.

By default, vnstat cron job runs as &#8220;nobody&#8221;, yet the database file &#8220;/var/lib/vnstat/venet0&#8243; was owned by root, changing its ownership to &#8220;nobody&#8221;, fixed the problem:

chown nobody:nobody /var/lib/vnstat/*

]]></description>
			<content:encoded><![CDATA[<p>On CentOS 5.4, the vnstat cron job generates an error:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Error: Unable create database backup &quot;/var/lib/vnstat/.venet0&quot;.</pre></div></div>

<p>By default, vnstat cron job runs as &#8220;nobody&#8221;, yet the database file &#8220;/var/lib/vnstat/venet0&#8243; was owned by root, changing its ownership to &#8220;nobody&#8221;, fixed the problem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> nobody:nobody <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>vnstat<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/centos-vnstat-error-unable-create-database-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find files and pass to du to get a human readable list sorted by size</title>
		<link>http://giantdorks.org/alain/find-files-and-pass-to-du-to-get-a-human-readable-list-sorted-by-size/</link>
		<comments>http://giantdorks.org/alain/find-files-and-pass-to-du-to-get-a-human-readable-list-sorted-by-size/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 08:31:23 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=436</guid>
		<description><![CDATA[I liked Jason&#8217;s solution of passing a file list to du via xargs to produce results sorted by size in human readable format, but wanted ability to limit file list by name and age. Combining the find command with du, worked out nicely:

find . -name &#34;*tar.bz2&#34; -mmin -120 -ls &#124; sort -k7rn &#124; awk '{print$NF}' [...]]]></description>
			<content:encoded><![CDATA[<p>I liked <a href="http://giantdorks.org/jason/2009/05/01/bash-one-liner-human-readable-sorted-du/">Jason&#8217;s solution</a> of passing a file list to <em>du</em> via <em>xargs</em> to produce results sorted by size in human readable format, but wanted ability to limit file list by name and age. Combining the <em>find</em> command with <em>du</em>, worked out nicely:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*tar.bz2&quot;</span> <span style="color: #660033;">-mmin</span> <span style="color: #660033;">-120</span> <span style="color: #660033;">-ls</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k7rn</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$NF}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sh</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">122M	./sls-monitor/830144.tar.bz2
98M	./sls-monitor/830156.tar.bz2
67M	./sls-off1/905895.tar.bz2
50M	./sls-off1/893748.tar.bz2
16M	./sls-off1/893759.tar.bz2
7.3M	./sls-off1/905897.tar.bz2
5.1M	./sls-off1/854850.tar.bz2
4.4M	./sls-monitor/804331.tar.bz2
3.8M	./sls-monitor/804333.tar.bz2
612K	./sls-off1/893755.tar.bz2
512K	./sls-off1/905898.tar.bz2</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/find-files-and-pass-to-du-to-get-a-human-readable-list-sorted-by-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Achieve faster file transfer times by running Rsync as a daemon</title>
		<link>http://giantdorks.org/alain/achieve-faster-file-transfer-times-by-running-rsync-as-a-daemon/</link>
		<comments>http://giantdorks.org/alain/achieve-faster-file-transfer-times-by-running-rsync-as-a-daemon/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 01:37:54 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=412</guid>
		<description><![CDATA[When syncing files over a trusted network, where speed matters more than someone&#8217;s ability to see contents of the transfer, might want to run rsync as a daemon instead of using remote shell as the transport.
In my tests, running rsync as a daemon produces file transfers almost twice as fast as when rsyncing over SSH.

Rsync [...]]]></description>
			<content:encoded><![CDATA[<p>When syncing files over a trusted network, where speed matters more than someone&#8217;s ability to see contents of the transfer, might want to run rsync as a daemon instead of using remote shell as the transport.</p>
<p>In my tests, running rsync as a daemon produces file transfers almost twice as fast as when rsyncing over SSH.</p>
<p><span id="more-412"></span></p>
<p>Rsync daemon can be run either on the box that&#8217;s sending data or receiving it. In this example, the box receiving data will run the rsync daemon &#8212; so we&#8217;ll be using rsync in push mode (&#8220;client&#8221; pushing to &#8220;server&#8221;). I suppose, the other way around (pull mode), could be considered more secure since the rsync module can be setup in read only mode.</p>
<p><em><strong>NOTE:</strong> the following setup should work on any Linux, but in my case the server was Debian 5.0.3 and client was Ubuntu 8.10.</em></p>
<p><strong>On the server:</strong></p>
<p>1. Create /etc/rsyncd.conf containing:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">uid = root
gid = root
max connections = 5
hosts allow = 192.168.1.5 192.168.1.77
socket options = SO_KEEPALIVE
&nbsp;
[modulename]
path = /path/to/dir
auth users = someuser
read only = no
secrets file = /etc/rsyncd.passwd</pre></td></tr></table></div>

<p>2. Create secrets file /etc/rsyncd.passwd containing:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">someuser:somepass</pre></td></tr></table></div>

<p>3. Debian rsync daemon startup script will complain if secrets file is world readable so we set perms so it isn&#8217;t:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsyncd.passwd</pre></div></div>

<p>4. Start up the daemon:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>rsync start</pre></div></div>

<p><em><strong>NOTE:</strong> any time /etc/rsyncd.conf is modified, daemon will need to be restarted.</em></p>
<p><strong>On the client:</strong></p>
<p>By default, rsync daemon on the server will prompt for password. You could supply a password file to suppress the prompt.</p>
<p>1. Create secrets file /etc/rsyncc.passwd containing:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">somepass</pre></td></tr></table></div>

<p>2. Invoke rsync with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rsync <span style="color: #660033;">--password-file</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rsyncc.passwd <span style="color: #660033;">--progress</span> <span style="color: #660033;">-rh</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>dir<span style="color: #000000; font-weight: bold;">/</span> someuser<span style="color: #000000; font-weight: bold;">@</span>server::modulename<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>remote<span style="color: #000000; font-weight: bold;">/</span>dir<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>The above will read password on the client from /etc/rsyncc.passwd and sync contents of /path/to/local/dir/ on the client to /path/to/dir/path/to/remote/dir/ on the server (modulename expands to path in /etc/rsyncd.conf on the server).</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/achieve-faster-file-transfer-times-by-running-rsync-as-a-daemon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SpamAssassin Bayes plugin brings me gift of 100% filter accuracy</title>
		<link>http://giantdorks.org/alain/spamassassin-bayes-plugin-brings-me-gift-of-100-filter-accuracy/</link>
		<comments>http://giantdorks.org/alain/spamassassin-bayes-plugin-brings-me-gift-of-100-filter-accuracy/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 04:09:56 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Spam]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=423</guid>
		<description><![CDATA[Dec 09 was the first month I had achieved 100% spam catch rate since I started filtering my own mail a few years ago. Thanks, SpamAssassin Bayes plugin! Merry Xmas to you as well!

------------------------------------
Stats for Dec 2009
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
160	392	1273	0	0
--------------------------------------------------------------
1825		Total messages
1665		Total Spam (Caught + Missed + Rejected)
91.23%		Spam as % of all mail
76.45%		% of Spam rejected by Postfix at [...]]]></description>
			<content:encoded><![CDATA[<p>Dec 09 was the first month I had achieved 100% spam catch rate since I started filtering my own mail a few years ago. Thanks, SpamAssassin Bayes plugin! Merry Xmas to you as well!</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">------------------------------------
Stats for Dec 2009
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
160	392	1273	0	0
--------------------------------------------------------------
1825		Total messages
1665		Total Spam (Caught + Missed + Rejected)
91.23%		Spam as % of all mail
76.45%		% of Spam rejected by Postfix at SMTP time
0%		False positive rate (Ham misclassified as Spam)
0%		False negative rate (Spam misclassified as Ham)
100.00%		Spam catch rate (Spam filter accuracy)
--------------------------------------------------------------</pre></div></div>

<p><span id="more-423"></span></p>
<p>Long version:</p>
<p>My company had switched to Google Apps for email and we saw an increase in the number of false negatives for spam sent to one of the email addresses published on our website. The amount was unbearable enough (a few dozen per day) that I asked our email guy to send mail from that alias to my personal email address to see if my anti spam setup could do better than Google&#8217;s. It did, but not well enough as the number of false negatives jumped from my usual 1-4 per month to 16 in Nov. The identification rate was still better than most commercial anti spam solutions out there (see <a href="http://www.pcworld.com/zoom?id=115885&amp;page=2&amp;type=simplechart&amp;zoomIdx=1">test results by PC World</a>, <a href="http://i.cmpnet.com/nc/1509/graphics/1509f2b.gif">test results by Network Computing</a> or <a href="http://www.pcmag.com/image_popup/0,1871,iid=19979,00.asp">test results by PC Magazine</a>), but seeing more than a couple of spams per month is too much for me, regardless of how good a rate it might represent:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">------------------------------------
Stats for Nov 2009
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
175	767	687	16	0
--------------------------------------------------------------
1645		Total messages
1470		Total Spam (Caught + Missed + Rejected)
89.36%		Spam as % of all mail
46.73%		% of Spam rejected by Postfix at SMTP time
0%		False positive rate (Ham misclassified as Spam)
.97%		False negative rate (Spam misclassified as Ham)
98.91%		Spam catch rate (Spam filter accuracy)
--------------------------------------------------------------</pre></div></div>

<p>The reason for the jump in false negatives, was that my primary anti spam tool (rejecting spam at SMTP time with Postfix) was hampered by the fact that this spam was forwarded to me after having been accepted by Google, as such, it was coming from Google&#8217;s SMTP servers and because Google MX servers aren&#8217;t listed in RBL, my MX would accept the spam.</p>
<p>Previously, the amount of spam that got through was low enough that I didn&#8217;t even bother with statistical analysis tools. But in Nov, I enabled/configured the Bayes plugin for SpamAssassin. Looks like this one piece is what I needed to achieve 100% spam filtering accuracy. 0 spam is a number I can live with!</p>
<p>When I have a spare minute, I&#8217;ll see about complementing my existing toolkit with a solution based on Markovian discrimination, which, if you believe the Wikipedia article about it, might make for a more accurate statistical analysis based spam filter than the Bayesian method.</p>
<p><em><strong>Update, Jan 13:</strong> I should note that after a few weeks, Google support finally came through with a solution which reduced false negatives from that particular email alias to zero. Aside from slow resolution time, I&#8217;m impressed with the quality of their filter.</em></p>
<p><em><strong>Update, Feb 12:</strong> Spoke too soon &#8212; so far in Feb, Google let 11 spams through. During the last two weeks of Jan, it let through 10 spams. While Google&#8217;s spam filter may be better than those of some of the other free email providers, it still allows through an unacceptable amount of spam and falls well below what properly configured SpamAssassin setup can achieve.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/spamassassin-bayes-plugin-brings-me-gift-of-100-filter-accuracy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comment out lines matching pattern with Sed</title>
		<link>http://giantdorks.org/alain/comment-out-lines-matching-pattern-with-sed/</link>
		<comments>http://giantdorks.org/alain/comment-out-lines-matching-pattern-with-sed/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 01:01:25 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=408</guid>
		<description><![CDATA[Let&#8217;s say you&#8217;ve got a file with the following lines:

cat file.txt 
leave me alone
leave me alone
comment me out
leave me alone
comment me out also
leave me alone

Comment out the lines that are begging for it:

sed -i '/comment me out/s/^/#/g' file.txt

Voila:

cat file.txt 
leave me alone
leave me alone
#comment me out
leave me alone
#comment me out also
leave me alone

]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you&#8217;ve got a file with the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> file.txt 
leave me alone
leave me alone
comment me out
leave me alone
comment me out also
leave me alone</pre></div></div>

<p>Comment out the lines that are begging for it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/comment me out/s/^/#/g'</span> file.txt</pre></div></div>

<p>Voila:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> file.txt 
leave me alone
leave me alone
<span style="color: #666666; font-style: italic;">#comment me out</span>
leave me alone
<span style="color: #666666; font-style: italic;">#comment me out also</span>
leave me alone</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/comment-out-lines-matching-pattern-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Future proof your certificate with a 2048 bit key</title>
		<link>http://giantdorks.org/alain/future-proof-your-certificate-with-a-2048-bit-key/</link>
		<comments>http://giantdorks.org/alain/future-proof-your-certificate-with-a-2048-bit-key/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 06:33:43 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=390</guid>
		<description><![CDATA[It was time to renew a couple of certs and it turned out that the CSR I had originally used was generated with a 512 bit key. Dynadot, who, by the way, offers a pretty sweet $15/year price on single root RapidSSL certs, suggested that I regenerate with a minimum of 1024 bits.
Indeed, it looks [...]]]></description>
			<content:encoded><![CDATA[<p>It was time to renew a couple of certs and it turned out that the CSR I had originally used was generated with a 512 bit key. Dynadot, who, by the way, offers <a href="http://www.dynadot.com/?6gM6H7D8s6Tk65">a pretty sweet $15/year price on single root RapidSSL certs</a>, suggested that I regenerate with a minimum of 1024 bits.</p>
<p>Indeed, it looks like 1024 bit key length is the minimum currently recommended. In fact, <a href="http://www.keylength.com/en/compare/">depending on whom you ask</a>, it may already be insufficient.</p>
<p>NIST guidelines are comparatively optimistic, but even according to their 2007 <a href="http://csrc.nist.gov/groups/ST/toolkit/key_management.html">Recommendation for Key Management</a>, time for 1024 bit keys is passing quick.</p>
<p><span id="more-390"></span></p>
<table id="general">
<tr>
<th>Algorithm security lifetimes</th>
<th>Symmetric key algorithms<br />(Encryption &amp; MAC)</th>
<th>FFC<br />(e.g., DSA, D-H)</th>
<th>IFC<br />(e.g., RSA)</th>
<th>ECC<br />(e.g., ECDSA)</th>
</tr>
<tr>
<td>Through 2010<br />(min. of 80 bits of strength)</td>
<td>2TDEA<br />3TDEA<br />AES-128<br />AES-192<br />AES-256</td>
<td>Minimum:<br />L = 1024;<br />N =160</td>
<td>Minimum:<br />k=1024</td>
<td>Minimum:<br />f=160</td>
</tr>
<tr>
<td>Through 2030<br />(min. of 112 bits of strength)</td>
<td>3TDEA<br />AES-128<br />AES-192<br />AES-256</td>
<td>Minimum:<br />L = 2048<br />N = 224 </td>
<td>Minimum:<br />k=2048</td>
<td>Minimum:<br />f=224</td>
</tr>
<tr>
<td>Beyond 2030<br />(min. of 128 bits of strength)</td>
<td>AES-128<br />AES-192<br />AES-256</td>
<td>Minimum:<br />L = 3072<br />N = 256</td>
<td>Minimum:<br />k=3072</td>
<td>Minimum:<br />f=256</td>
</tr>
</table>
<p>The trade off with longer key length is of course speed, decryption speed in particular, as that&#8217;s what the server will be doing. The penalty is significant. According to a study titled &#8220;Performance Analysis of Secure Web Server Based on SSL&#8221;, doubling of the key length resulted in nearly 8x performance penalty:</p>
<table id="general">
<tr>
<th>RSA Key Size</th>
<th>Performance</th>
</tr>
<tr>
<td>512 bit</td>
<td>11 ms</td>
</tr>
<tr>
<td>1024 bit</td>
<td>68 ms</td>
</tr>
<tr>
<td>2048 bit</td>
<td>481 ms</td>
</tr>
</table>
<p>In my case, I&#8217;m working with low volume applications, 2048 bit key length should be fine:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-rand</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #660033;">-out</span> your.name.key <span style="color: #000000;">2048</span>
openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-nodes</span> <span style="color: #660033;">-key</span> your.name.key <span style="color: #660033;">-out</span> your.name.csr</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/future-proof-your-certificate-with-a-2048-bit-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save your keyboard with SED</title>
		<link>http://giantdorks.org/alain/save-your-keyboard-with-sed/</link>
		<comments>http://giantdorks.org/alain/save-your-keyboard-with-sed/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 03:36:28 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=382</guid>
		<description><![CDATA[Once again I did something that changed the host key (like rebuild the host). Now I&#8217;m trying to SSH to it and get the usual warning from SSH that the key is different. In the past, I&#8217;d open up ~/.ssh/known_hosts with VIM, enter &#8220;:&#8221; and line number SSH referred to, hit &#8220;dd&#8221; to delete it, [...]]]></description>
			<content:encoded><![CDATA[<p>Once again I did something that changed the host key (like rebuild the host). Now I&#8217;m trying to SSH to it and get the usual warning from SSH that the key is different. In the past, I&#8217;d open up ~/.ssh/known_hosts with VIM, enter &#8220;:&#8221; and line number SSH referred to, hit &#8220;dd&#8221; to delete it, then &#8220;:wq&#8221; to write and quit VIM, only to get warned again that the key for the IP address host is known by has also changed and do the whole dance over again.</p>
<p>But tonight is different. Tonight I&#8217;m gonna give the keyboard a break.</p>
<p>This will delete line 93 from known_hosts:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> 93d ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>known_hosts</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/save-your-keyboard-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revive a dead iPhone following complete battery discharge</title>
		<link>http://giantdorks.org/alain/revive-dead-iphone-following-complete-battery-discharge/</link>
		<comments>http://giantdorks.org/alain/revive-dead-iphone-following-complete-battery-discharge/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 21:02:15 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Phones]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=363</guid>
		<description><![CDATA[I guess I must have let the battery on the iPhone completely discharge, as I found it motionless and unresponsive last night on my desk. Plugged it in, still nothing &#8212; won&#8217;t start up. Left it charging overnight, still no luck. Followed the reset procedure: 

Hold down power and home buttons together until the Apple [...]]]></description>
			<content:encoded><![CDATA[<p>I guess I must have let the battery on the iPhone completely discharge, as I found it motionless and unresponsive last night on my desk. Plugged it in, still nothing &#8212; won&#8217;t start up. Left it charging overnight, still no luck. Followed the reset procedure: </p>
<ul>
<li>Hold down power and home buttons together until the Apple logo appears</li>
</ul>
<p>And it came back to life. The battery was empty, plugged in, now it&#8217;s charging. It&#8217;s a relief, weird behavior, though, I think. I&#8217;ve let the battery on the other phones I&#8217;ve had over the years (Nokia, BlackBerry, Sony, Siemens, etc, etc) drain completely lots of times. Plugging in the charger always just let me start them up again with no issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/revive-dead-iphone-following-complete-battery-discharge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to calculate spam statistics</title>
		<link>http://giantdorks.org/alain/shell-script-to-calculate-spam-statistics/</link>
		<comments>http://giantdorks.org/alain/shell-script-to-calculate-spam-statistics/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 04:17:01 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Spam]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=372</guid>
		<description><![CDATA[Cooked up a little shell script to produce monthly email statistics such as amount of email received, how much of it was spam, percentage of spam correctly identified, etc. Previously, I had manually ran the numbers and input into OpenOffice Calc to get the stats &#8212; boring!
Example output:

root@dpork:~# spam-stats-month Aug 2009
&#160;
------------------------------------
Stats for Aug 2009
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
151	122	3444	7	0
--------------------------------------------------------------
3724		Total messages
3573		Total [...]]]></description>
			<content:encoded><![CDATA[<p>Cooked up a little shell script to produce monthly email statistics such as amount of email received, how much of it was spam, percentage of spam correctly identified, etc. Previously, I had manually ran the numbers and input into OpenOffice Calc to get the stats &#8212; boring!</p>
<p>Example output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@dpork:~# spam-stats-month Aug 2009
&nbsp;
------------------------------------
Stats for Aug 2009
------------------------------------
Ham	SpamC	SpamR	SpamM	HamC
151	122	3444	7	0
--------------------------------------------------------------
3724		Total messages
3573		Total Spam (Caught + Missed + Rejected)
95.94%		Spam as % of all mail
96.38%		% of Spam rejected by Postfix at SMTP time
0%		False positive rate (Ham misclassified as Spam)
.18%		False negative rate (Spam misclassified as Ham)
99.80%		Spam catch rate (Spam filter accuracy)
--------------------------------------------------------------</pre></div></div>

<p><span id="more-372"></span></p>
<p>My anti spam arsenal consists of Postfix anti-spam measures which reject obvious spam at the SMTP level and SpamAssassin via amavisd-new, which scans mail that was accepted for delivery. The latter consists of network tests (Razor, Pyzor), Bayes statistical analysis, FuzzyOcr for the image spam and some custom pattern matching rules by me. </p>
<p>After SA is done analyzing and tagging a message, it hands it back to Postfix, which then hands it to Cyrus for final delivery. Cyrus IMAP provides a powerful Sieve filtering interface, which I use to sort mail into my IMAP folders. My Sieve filter sorts spam over a certain threshold into the SpamCaught folder, while marking message with really high scores as read, so I don&#8217;t see them, the low scoring stuff I like to review and manually move any false positives to HamCaught folder and any false negatives to SpamMissed folder, which my nightly Bayes train script scans and learns from.</p>
<p>The spam stats script runs on the mail server (same Debian box runs Postfix and Cyrus), and very simply loops through my IMAP folders counting messages in the Inbox (ham), SpamCaught (correctly identified spam), SpamMissed (false negatives), HamCaught (false positives) and also parses mail logs to get a total for messages rejected by Postfix. It then does some basic bash arithmetic and calls bc to calculate percentages.</p>
<p>And here&#8217;s the script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Get some spam numbers</span>
<span style="color: #666666; font-style: italic;"># Usage: spam-stats-month Oct 2009</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin; <span style="color: #7a0874; font-weight: bold;">export</span> PATH
&nbsp;
  <span style="color: #666666; font-style: italic;"># Verify input</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> $<span style="color: #000000;">1</span> =~ <span style="color: #ff0000;">&quot;\b[A-Z][a-z]{2}\b&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> $<span style="color: #000000;">2</span> =~ <span style="color: #ff0000;">&quot;\b[0-9]{4}\b&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Usage error..<span style="color: #000099; font-weight: bold;">\n</span> Example: spam-stats-month Oct 2009<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">127</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ----------------------------------------------------------------- #</span>
<span style="color: #666666; font-style: italic;"># Convert text month input date format to numeric for use with &quot;ls&quot;</span>
<span style="color: #666666; font-style: italic;"># (e.g. &quot;Nov 2009&quot; to &quot;2009-11&quot;&quot;)</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        Jan<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;01&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Feb<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;02&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Mar<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;03&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Apr<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;04&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        May<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;05&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Jun<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;06&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Jul<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;07&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Aug<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;08&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Sep<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;09&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Oct<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Nov<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;11&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        Dec<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">nummon</span>=<span style="color: #ff0000;">&quot;12&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #666666; font-style: italic;"># Construct numeric date</span>
<span style="color: #007800;">numdate</span>=$<span style="color: #000000;">2</span>-<span style="color: #007800;">$nummon</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#1. Ham</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>cyrus<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>domain<span style="color: #000000; font-weight: bold;">/</span>g<span style="color: #000000; font-weight: bold;">/</span>gd.org<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>ak<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">Ham</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">*</span>. <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$numdate</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#2. SpamRejected</span>
<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">file</span></span>=<span style="color: #ff0000;">&quot;/tmp/spam.stats.$1.rejected&quot;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$file</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$file</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$file</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mail.log<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$numdate</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$NF}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">zgrep</span> <span style="color: #ff0000;">&quot;postfix&quot;</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;reject:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^$1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$file</span>
  <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #007800;">SpamR</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{s+=$0} END {print s}'</span> <span style="color: #007800;">$file</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#3. SpamCaught</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>cyrus<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>domain<span style="color: #000000; font-weight: bold;">/</span>g<span style="color: #000000; font-weight: bold;">/</span>gd.org<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>ak<span style="color: #000000; font-weight: bold;">/</span>SpamCaught<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">SpamC1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">*</span>. <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$numdate</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SpamC2</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>amavis<span style="color: #000000; font-weight: bold;">/</span>virusmails<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$numdate</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SpamC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$SpamC1</span> + <span style="color: #007800;">$SpamC2</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#4. SpamMissed</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>cyrus<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>domain<span style="color: #000000; font-weight: bold;">/</span>g<span style="color: #000000; font-weight: bold;">/</span>gd.org<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>ak<span style="color: #000000; font-weight: bold;">/</span>SpamMissed<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">SpamM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">*</span>. <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$numdate</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#5. HamCaught</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>cyrus<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>domain<span style="color: #000000; font-weight: bold;">/</span>g<span style="color: #000000; font-weight: bold;">/</span>gd.org<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>ak<span style="color: #000000; font-weight: bold;">/</span>HamCaught<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">HamC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">*</span>. <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$numdate</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Stats for $1 $2&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Ham<span style="color: #000099; font-weight: bold;">\t</span>SpamC<span style="color: #000099; font-weight: bold;">\t</span>SpamR<span style="color: #000099; font-weight: bold;">\t</span>SpamM<span style="color: #000099; font-weight: bold;">\t</span>HamC&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$Ham</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$SpamC</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$SpamR</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$SpamM</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #007800;">$HamC</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Calc percentages</span>
<span style="color: #007800;">TotalMsg</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$Ham</span> + <span style="color: #007800;">$SpamC</span> + <span style="color: #007800;">$SpamR</span> + <span style="color: #007800;">$SpamM</span> + <span style="color: #007800;">$HamC</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">TotalSpam</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$SpamC</span> + <span style="color: #007800;">$SpamR</span> + <span style="color: #007800;">$SpamM</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">TotalSpamI</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$SpamC</span> + <span style="color: #007800;">$SpamR</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">FPpercent</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$HamC</span>*100/<span style="color: #007800;">$TotalMsg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">FNpercent</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$SpamM</span>*100/<span style="color: #007800;">$TotalMsg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SpamPercent</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$TotalSpam</span>*100/<span style="color: #007800;">$TotalMsg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SpamRPercent</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$SpamR</span>*100/<span style="color: #007800;">$TotalSpam</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SpamCatchRate</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2;  <span style="color: #007800;">$TotalSpamI</span>*100/<span style="color: #007800;">$TotalSpam</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TotalMsg</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Total messages&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TotalSpam</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Total Spam (Caught + Missed + Rejected)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SpamPercent</span>%<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Spam as % of all mail&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SpamRPercent</span>%<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>% of Spam rejected by Postfix at SMTP time&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FPpercent</span>%<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>False positive rate (Ham misclassified as Spam)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FNpercent</span>%<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>False negative rate (Spam misclassified as Ham)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SpamCatchRate</span>%<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Spam catch rate (Spam filter accuracy)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-script-to-calculate-spam-statistics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu running in low graphics mode following kernel update</title>
		<link>http://giantdorks.org/alain/ubuntu-running-in-low-graphics-mode-following-kernel-update/</link>
		<comments>http://giantdorks.org/alain/ubuntu-running-in-low-graphics-mode-following-kernel-update/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 06:35:25 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=345</guid>
		<description><![CDATA[I had gotten the optimal 1366&#215;768 resolution working on the Dell Mini 10 with the optional HD display (Poulsbo chipset / Intel GMA500 video) by using the drivers provided by the Ubuntu Mobile Team.1
It&#8217;s been working great for over a month until this morning, when instead of a login screen, I was greeted with an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2009/11/err1.jpg" align="left" />I had gotten the optimal 1366&#215;768 resolution working on the Dell Mini 10 with the optional HD display (Poulsbo chipset / Intel GMA500 video) by using the drivers provided by the Ubuntu Mobile Team.<sup>1</sup></p>
<p>It&#8217;s been working great for over a month until this morning, when instead of a login screen, I was greeted with an error: &#8220;Ubuntu running in low graphics mode&#8221;.</p>
<p>What&#8217;s up with that?  The APT log contained the explanation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="text" style="font-family:monospace;"> * Running DKMS auto installation service for kernel 2.6.28-16-generic        
 *  psb-kernel-source (4.41.1)...        psb-kernel-source (4.41.1): AUTOINSTALL not set in its dkms.conf.</pre></td></tr></table></div>

<p>I guess I could set AUTOINSTALL for the psb-kernel-source module to &#8220;Yes&#8221;. I&#8217;ll think about it, meanwhile, a manual fix is easy enough:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">sudo dpkg-reconfigure psb-kernel-source
sudo shutdown -r now</pre></td></tr></table></div>

<p><span id="more-345"></span></p>
<p>POW. Back in business.</p>
<p><sup>1</sup> By the way, all I had to do to get full resolution working in the first place, as I recall, was add the Ubuntu Mobile Team sources to my /etc/apt/sources.list:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">deb http://ppa.launchpad.net/ubuntu-mobile/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/ubuntu-mobile/ppa/ubuntu jaunty main</pre></td></tr></table></div>

<p>Install the drivers and reboot:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">sudo aptitude update
sudo aptitude install psb-kernel-headers psb-kernel-source xserver-xorg-video-psb
sudo shutdown -r now</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/ubuntu-running-in-low-graphics-mode-following-kernel-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shell one liner to produce a delimited file with massive number of date ranges</title>
		<link>http://giantdorks.org/alain/shell-one-liner-to-produce-a-delimited-file-with-massive-number-of-date-ranges/</link>
		<comments>http://giantdorks.org/alain/shell-one-liner-to-produce-a-delimited-file-with-massive-number-of-date-ranges/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 05:38:44 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=340</guid>
		<description><![CDATA[A project I&#8217;m working required a comma delimited file containing date ranges, in one week increments, from July 1987 to the present. That&#8217;s 1166 week ranges. What sounds like a potentially time consuming ordeal, takes about 10 sec to produce with the following shell one liner:

for n in $&#40;seq 0 1166&#41;; \
do echo -e \
$&#40;date [...]]]></description>
			<content:encoded><![CDATA[<p>A project I&#8217;m working required a comma delimited file containing date ranges, in one week increments, from July 1987 to the present. That&#8217;s 1166 week ranges. What sounds like a potentially time consuming ordeal, takes about 10 sec to produce with the following shell one liner:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> n <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">0</span> <span style="color: #000000;">1166</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; \
<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> \
$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">/%</span>d<span style="color: #000000; font-weight: bold;">/%</span>Y <span style="color: #660033;">--date</span>=<span style="color: #ff0000;">&quot;1987-07-01 +<span style="color: #007800;">$n</span> week&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #ff0000;">&quot;,&quot;</span>\
$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">/%</span>d<span style="color: #000000; font-weight: bold;">/%</span>Y <span style="color: #660033;">--date</span>=<span style="color: #ff0000;">&quot;1987-07-01 +<span style="color: #007800;">$n</span> week +6 day&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> \
<span style="color: #000000; font-weight: bold;">&gt;&gt;</span> date.ranges; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><span id="more-340"></span></p>
<p>The result:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">07/01/1987,07/07/1987
07/08/1987,07/14/1987
07/15/1987,07/21/1987
...
10/21/2009,10/27/2009
10/28/2009,11/03/2009
11/04/2009,11/10/2009</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-one-liner-to-produce-a-delimited-file-with-massive-number-of-date-ranges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use apt-file to find a package that provides a program</title>
		<link>http://giantdorks.org/alain/find-a-package-that-provides-a-program/</link>
		<comments>http://giantdorks.org/alain/find-a-package-that-provides-a-program/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 23:41:18 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[APT]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=324</guid>
		<description><![CDATA[If you&#8217;re looking for a program and need to find a package that provides it, AND your package manager is APT (e.g. you&#8217;re running Debian or one of its many derivatives, like Ubuntu), you, Sir, got a couple of options.
One way is to search package contents online at debian.org, or you could use apt-file. 

First, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2009/11/d3b1.png" align="left" />If you&#8217;re looking for a program and need to find a package that provides it, AND your package manager is APT (e.g. you&#8217;re running Debian or one of its many derivatives, like Ubuntu), you, Sir, got a couple of options.</p>
<p>One way is to search package contents online at <a href="http://www.debian.org/distrib/packages#search_contents">debian.org</a>, or you could use apt-file. </p>
<p><span id="more-324"></span></p>
<p>First, we install it and update its database:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">sudo aptitude install apt-file
sudo apt-file update</pre></td></tr></table></div>

<p>Now, let&#8217;s find what package provides command mimencode (since I&#8217;m looking for a program, I&#8217;ll prepend the search with &#8220;bin&#8221; since that&#8217;s where programs typically live):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">apt-file search bin/mimencode
metamail: usr/bin/mimencode</pre></td></tr></table></div>

<p>So I&#8217;ll need to install package &#8220;metamail&#8221; to get program &#8220;mimencode&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">sudo aptitude install metamail
which mimencode
/usr/bin/mimencode</pre></td></tr></table></div>

<p>Sweet.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/find-a-package-that-provides-a-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge old revisions of WordPress blog posts</title>
		<link>http://giantdorks.org/alain/purge-old-revisions-of-wordpress-blog-posts/</link>
		<comments>http://giantdorks.org/alain/purge-old-revisions-of-wordpress-blog-posts/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 16:05:55 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=313</guid>
		<description><![CDATA[WordPress helpfully creates revisions of blog posts. If you&#8217;re concerned about a number of rows in the wp_posts table, you could delete old revisions. Let&#8217;s say we want to delete revisions older than 7 days:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SELECT COUNT&#40;*&#41; FROM wp_posts WHERE post_type = 'revision';
+----------+
&#124; COUNT&#40;*&#41; &#124;
+----------+
&#124;      110 &#124; 
+----------+
SELECT COUNT&#40;*&#41; FROM wp_posts [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress helpfully creates revisions of blog posts. If you&#8217;re concerned about a number of rows in the wp_posts table, you could delete old revisions. Let&#8217;s say we want to delete revisions older than 7 days:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'revision'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span>      <span style="color: #cc66cc;">110</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'revision'</span> <span style="color: #993333; font-weight: bold;">AND</span> post_date <span style="color: #66cc66;">&lt;</span> DATE_ADD<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> INTERVAL <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">7</span> DAY<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span>       <span style="color: #cc66cc;">84</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'revision'</span> <span style="color: #993333; font-weight: bold;">AND</span> post_date <span style="color: #66cc66;">&lt;</span> DATE_ADD<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> INTERVAL <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">7</span> DAY<span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'revision'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span>
<span style="color: #66cc66;">|</span>       <span style="color: #cc66cc;">26</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------+</span></pre></td></tr></table></div>

<p>If you&#8217;re running WordPress MU, the process is the same, just need to specify the right table as each WPMU blog has its own. See this post for <a href="http://giantdorks.org/alain/shell-one-liner-to-identify-which-mysql-database-tables-are-used-for-which-wordpress-mu-blog/">how to identify WPMU blog numbers and corresponding URLs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/purge-old-revisions-of-wordpress-blog-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attach to an existing X session with x11vnc over SSH</title>
		<link>http://giantdorks.org/alain/attach-to-an-existing-gdm-session-with-vnc-over-ssh/</link>
		<comments>http://giantdorks.org/alain/attach-to-an-existing-gdm-session-with-vnc-over-ssh/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 20:14:02 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=280</guid>
		<description><![CDATA[Most of the stuff I do is via the shell, but once in a while need to attach to an existing X session on my work desktop. My requirements are that the method:

Uses SSH for authentication
Tunnels VNC traffic over SSH for security and so no additional ports need to be opened

x11vnc is what I&#8217;ve been [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the stuff I do is via the shell, but once in a while need to attach to an existing X session on my work desktop. My requirements are that the method:</p>
<ul>
<li>Uses SSH for authentication</li>
<li>Tunnels VNC traffic over SSH for security and so no additional ports need to be opened</li>
</ul>
<p><a href="http://www.karlrunge.com/x11vnc/">x11vnc</a> is what I&#8217;ve been using. Here&#8217;s a little shell script I wrote that will take user@hostname as a variable, enumerate an existing GDM session on the remote computer, create an SSH tunnel and attach to it via VNC. It uses aggressive compression, which looks a bit ugly but still works over a low bandwidth connection. The auth file enumeration bit works with Gnome, but could probably be adapted for use with other window managers.</p>
<p><span id="more-280"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
die <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #660033;">-q</span> <span style="color: #ff0000;">'[a-zA-Z0-9]\@[a-zA-Z0-9]'</span> <span style="color: #000000; font-weight: bold;">||</span> die <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Missing username and host, try:<span style="color: #000099; font-weight: bold;">\n</span> ./vnc.sh user@host<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #007800;">USERHOST</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">USER</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$USERHOST</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #ff0000;">'{print$1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">AUTHFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$USERHOST</span> <span style="color: #ff0000;">'ls -la /tmp | grep $USER | grep gdm'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$NF}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; ------------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Attempting to use the following variables:&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; ------------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; USERHOST... &quot;</span> <span style="color: #007800;">$USERHOST</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; USER....... &quot;</span> <span style="color: #007800;">$USER</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; AUTHFILE... &quot;</span> <span style="color: #007800;">$AUTHFILE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">3</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-f</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">5900</span>:localhost:<span style="color: #000000;">5900</span> <span style="color: #007800;">$USERHOST</span> <span style="color: #ff0000;">'x11vnc -noxdamage -display :0 -auth'</span> <span style="color: #007800;">$AUTHFILE</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> vncviewer <span style="color: #660033;">-encodings</span> <span style="color: #ff0000;">&quot;copyrect tight zrle hextile&quot;</span> localhost:<span style="color: #000000;">0</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/attach-to-an-existing-gdm-session-with-vnc-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple nmap ping sweep and host scan script</title>
		<link>http://giantdorks.org/alain/nmap-ping-sweep-and-host-scan-script/</link>
		<comments>http://giantdorks.org/alain/nmap-ping-sweep-and-host-scan-script/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 12:41:33 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=261</guid>
		<description><![CDATA[
1
2
3
4
5
sudo -s
if &#91; -f /tmp/nmap.* &#93;; then rm /tmp/nmap.*; fi
nmap -sP -PA 192.168.0.0/24 &#62;&#62; /tmp/nmap.sweep
for h in $&#40;grep Host /tmp/nmap.sweep &#124; awk '{print$2}'&#41;; do $c -PN -A $h &#62;&#62; /tmp/nmap.scan; done
less /tmp/nmap.scan

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.<span style="color: #000000; font-weight: bold;">*</span>; <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">nmap</span> <span style="color: #660033;">-sP</span> <span style="color: #660033;">-PA</span> 192.168.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.sweep
<span style="color: #000000; font-weight: bold;">for</span> h <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> Host <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.sweep <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">$c</span> <span style="color: #660033;">-PN</span> <span style="color: #660033;">-A</span> <span style="color: #007800;">$h</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.scan; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #c20cb9; font-weight: bold;">less</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>nmap.scan</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/nmap-ping-sweep-and-host-scan-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to access the Internet using a cell phone as a bluetooth modem with Ubuntu Laptop</title>
		<link>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem-on-ubuntu-laptop/</link>
		<comments>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem-on-ubuntu-laptop/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 04:28:05 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Phones]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=57</guid>
		<description><![CDATA[This is a (long overdue) follow up on my ancient post on how to do this on a Windows laptop. It's been working on my Dell Inspiron 1501 like a champ for a couple years now, just set this up on my new a Dell Mini 10, so might as well post the steps while they're still fresh in memory (my RAM gets purged regularly, it seems).]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-18" src="http://giantdorks.org/alain/files/2007/12/ubun7u_vect0rized.png" alt="ubun7u_vect0rized" width="190" height="160" align="left" />This is a (long overdue) follow up on my ancient <a href="http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem/">post on how to setup a Nokia E62 as a bluetooth modem on a Windows laptop</a>. It&#8217;s been a couple of years now since I&#8217;ve purged the Winblows partition from my Dell Inspiron 1501 and it&#8217;s been happily running Ubuntu using the E62 to get to the Internets. Just got a Dell Mini 10 for work, so might as well post the steps while they&#8217;re still fresh in memory (my RAM gets regularly purged, as it turns out).</p>
<p><span id="more-57"></span></p>
<p><strong>Requirements</strong>: Any bluetooth enabled laptop and cellular phone should do, however, the steps below have been verified to work with Ubuntu 8.10 and 9.04 running on Dell Inspiron 1501 and Dell Mini 10. The phone used was Nokia E62.</p>
<p>I&#8217;ve already covered enabling bluetooth and connecting the two devices, so I&#8217;ll jump right into the bluetooth config. First, let&#8217;s install some software:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># aptitude install bluez-gnome bluez-utils wvdial</pre></div></div>

<p>Identify the MAC address of your phone and channel used for Dial-Up Networking:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># hcitool scan
Scanning ...
00:18:C5:2A:xx:xx	E62
# sdptool browse 00:18:C5:2A:xx:xx | grep -A10 &quot;Dial-Up Networking&quot; | grep Channel
Channel: 1</pre></div></div>

<p>Then enter the values. Below are mine, edit to fit your configuration.</p>
<p>My rfcomm config:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># cat /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind yes;
device 00:18:C5:2A:xx:xx;
channel 1;
comment &quot;Dial-up networking&quot;;
}</pre></div></div>

<p>My wvdial config:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># cat /etc/wvdial.conf
[Dialer Defaults]
Phone =
Username =
Password =
New PPPD = yes
[Dialer E62]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 +FCLASS=0
Init3 = AT+CGDCONT=, ,&quot;wap.cingular&quot;
Modem = /dev/rfcomm0
Phone = *99***1#
Username = WAP@CINGULARGPRS.COM
Password = CINGULAR1
New PPPD = yes
BAUD = 460800
Stupid Mode = 1</pre></div></div>

<p>Restart bluetooth:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># /etc/init.d/bluetooth restart</pre></div></div>

<p>Now let&#8217;s attempt to connect:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># wvdial E62</pre></div></div>

<p>If all is well, you should see something like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">--&gt; WvDial: Internet dialer version 1.60
--&gt; Cannot get information for serial port.
--&gt; Initializing modem.
--&gt; Sending: ATZ
ATZ
OK
--&gt; Sending: ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &amp;C1 &amp;D2 +FCLASS=0
OK
--&gt; Sending: AT+CGDCONT=, ,&quot;wap.cingular&quot;
AT+CGDCONT=, ,&quot;wap.cingular&quot;
OK
--&gt; Modem initialized.
--&gt; Sending: ATDT*99***1#
--&gt; Waiting for carrier.
ATDT*99***1#
CONNECT
~[7f]}#@!}!} } }2}#}$@#}!}$}%\}&quot;}&amp;} }*} } g}%~
--&gt; Carrier detected.  Starting PPP immediately.
--&gt; Starting pppd at Sun Oct 11 21:22:26 2009
--&gt; Pid of pppd: 20902
--&gt; Using interface ppp0
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; local  IP address 10.84.103.246
--&gt; pppd: ��?[08]
--&gt; remote IP address 10.6.6.6
--&gt; pppd: ��?[08]
--&gt; primary   DNS address 172.18.7.170
--&gt; pppd: ��?[08]
--&gt; secondary DNS address 172.18.7.170
--&gt; pppd: ��?[08]</pre></div></div>

<p>&#8220;Ifconfig&#8221; should show you a ppp0 device with an IP address and you should be able to access the Internet.</p>
<p>To disconnect, hit CTRL+C:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Caught signal 2:  Attempting to exit gracefully...
--&gt; Terminating on signal 15
--&gt; pppd: ��?[08]
--&gt; Connect time 0.9 minutes.
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; pppd: ��?[08]
--&gt; Disconnecting at Sun Oct 11 21:23:23 2009</pre></div></div>

<p>The end.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem-on-ubuntu-laptop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fdisk problems with partitions over 2TB</title>
		<link>http://giantdorks.org/alain/fdisk-problems-with-partitions-over-2tb/</link>
		<comments>http://giantdorks.org/alain/fdisk-problems-with-partitions-over-2tb/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 07:10:12 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=236</guid>
		<description><![CDATA[Partitioned a 4.2TB volume with fdisk, created a file system and all I got for was a lousy 2TB. WTF? fdisk man page explains:

fdisk  doesn’t  understand  GUID  Partition Table (GPT) and it is not designed for large 
partitions. In particular case use more advanced GNU parted(8).

Ok, parted it is then..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# aptitude [...]]]></description>
			<content:encoded><![CDATA[<p>Partitioned a 4.2TB volume with fdisk, created a file system and all I got for was a lousy 2TB. WTF? fdisk man page explains:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">fdisk  doesn’t  understand  GUID  Partition Table (GPT) and it is not designed for large 
partitions. In particular case use more advanced GNU parted(8).</pre></div></div>

<p>Ok, parted it is then..</p>
<p><span id="more-236"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="text" style="font-family:monospace;"># aptitude install parted
# parted /dev/xvde
&nbsp;
(parted) mklabel gpt
(parted) mkpart primary 0 -1
(parted) print
&nbsp;
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvde: 4548GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
&nbsp;
Number  Start   End     Size    File system  Name     Flags
1       17.4kB  4548GB  4548GB               primary  
&nbsp;
# mkfs.xfs /dev/xvde1 -f
# mount /dev/xvde1 /mnt/disk2
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            247G   58G  177G  25% /
tmpfs                 2.0G     0  2.0G   0% /lib/init/rw
udev                   10M   28K   10M   1% /dev
tmpfs                 2.0G  4.0K  2.0G   1% /dev/shm
/dev/xvdc1            2.0T  1.1T  939G  55% /mnt/disk1
/dev/xvde1            4.2T  4.2M  4.2T   1% /mnt/disk2</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/fdisk-problems-with-partitions-over-2tb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy way to update site URL when moving a WordPress blog to a new location</title>
		<link>http://giantdorks.org/alain/how-to-update-blog-url-when-moving-a-wordpress-install-to-a-new-location/</link>
		<comments>http://giantdorks.org/alain/how-to-update-blog-url-when-moving-a-wordpress-install-to-a-new-location/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 06:18:28 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=103</guid>
		<description><![CDATA[Let&#8217;s say a WordPress blog previously accessible via http://old/ is now at http://new/. You&#8217;ve updated the Apache config, yet when accessing http://new/, you get redirected to http://old/, which no longer exists. 
This is because WordPress still considers itself at the old URL. You could use the following SQL find/replace old URL instances with new, directly [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say a WordPress blog previously accessible via http://old/ is now at http://new/. You&#8217;ve updated the Apache config, yet when accessing http://new/, you get redirected to http://old/, which no longer exists. </p>
<p>This is because WordPress still considers itself at the old URL. You could use the following SQL find/replace old URL instances with new, directly in the database:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> wp_options <span style="color: #993333; font-weight: bold;">SET</span> option_value <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>option_value<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://old/'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://new/'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>But wait, you&#8217;re not done, there are more places to update..</p>
<p><span id="more-103"></span><br />
There are probably references to the old URL elsewhere as well. The ones I found were in the post_content and guid columns of the wp_posts table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> wp_posts <span style="color: #993333; font-weight: bold;">SET</span> post_content <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>post_content<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://old/'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://new/'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">UPDATE</span> wp_posts <span style="color: #993333; font-weight: bold;">SET</span> guid <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>guid<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://old/'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://new/'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> post_content <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_content <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%http://old%'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
<span style="color: #66cc66;">|</span> post_content <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
<span style="color: #66cc66;">|</span>            <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> post_content <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_content <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%http://new%'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
<span style="color: #66cc66;">|</span> post_content <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
<span style="color: #66cc66;">|</span>           <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">--------------+</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> guid <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> guid <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%http://old%'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span>
<span style="color: #66cc66;">|</span> guid <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span>
<span style="color: #66cc66;">|</span>    <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> guid <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> guid <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%http://new%'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span>
<span style="color: #66cc66;">|</span> guid <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span>
<span style="color: #66cc66;">|</span>   <span style="color: #cc66cc;">89</span> <span style="color: #66cc66;">|</span> 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------+</span></pre></td></tr></table></div>

<p>If you&#8217;re running WordPress MU, the process is the same, just need to specify the right table as each WPMU blog has its own. See this post for <a href="http://giantdorks.org/alain/shell-one-liner-to-identify-which-mysql-database-tables-are-used-for-which-wordpress-mu-blog/">how to enumerate WPMU blog numbers and URLs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/how-to-update-blog-url-when-moving-a-wordpress-install-to-a-new-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell one liner to identify which MySQL database tables are used for which WordPress MU blog</title>
		<link>http://giantdorks.org/alain/shell-one-liner-to-identify-which-mysql-database-tables-are-used-for-which-wordpress-mu-blog/</link>
		<comments>http://giantdorks.org/alain/shell-one-liner-to-identify-which-mysql-database-tables-are-used-for-which-wordpress-mu-blog/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 07:11:37 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=308</guid>
		<description><![CDATA[With WordPress MU, all blogs share the same database. A number is added to standard WordPress table names for each blog. Main blog is usually wp_1_xxx, second blog that was created is wp_2_xxx, etc.
To modify a WPMU blog directly in the DB, one would usually want to identify which tables are used for which blog, [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress MU, all blogs share the same database. A number is added to standard WordPress table names for each blog. Main blog is usually wp_1_xxx, second blog that was created is wp_2_xxx, etc.</p>
<p>To modify a WPMU blog directly in the DB, one would usually want to identify which tables are used for which blog, to ensure the correct blog is being modified. Here’s a little shell one liner to do just that:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;mysql giantdorks --skip-column-names -Be&quot;</span>; <span style="color: #007800;">TBS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$CMD</span> <span style="color: #ff0000;">&quot;show tables like 'wp%options'&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">for</span> TB <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TBS</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">URL</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$CMD</span> <span style="color: #ff0000;">&quot;select option_value from <span style="color: #007800;">$TB</span> where option_name='siteurl'&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$TB</span> is <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #007800;">$URL</span>; <span style="color: #000000; font-weight: bold;">done</span>
wp_1_options is <span style="color: #000000; font-weight: bold;">for</span> http:<span style="color: #000000; font-weight: bold;">//</span>giantdorks.org<span style="color: #000000; font-weight: bold;">/</span>
wp_2_options is <span style="color: #000000; font-weight: bold;">for</span> http:<span style="color: #000000; font-weight: bold;">//</span>giantdorks.org<span style="color: #000000; font-weight: bold;">/</span>alain<span style="color: #000000; font-weight: bold;">/</span>
wp_3_options is <span style="color: #000000; font-weight: bold;">for</span> http:<span style="color: #000000; font-weight: bold;">//</span>giantdorks.org<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-one-liner-to-identify-which-mysql-database-tables-are-used-for-which-wordpress-mu-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell one liner to pad filenames starting with single digit year with a zero</title>
		<link>http://giantdorks.org/alain/shell-one-liner-to-pad-filenames-starting-with-single-digit-year-with-a-zero/</link>
		<comments>http://giantdorks.org/alain/shell-one-liner-to-pad-filenames-starting-with-single-digit-year-with-a-zero/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 05:33:54 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=97</guid>
		<description><![CDATA[Pad filenames starting with a single digit year (e.g. 1, 2, etc) with a zero while leaving filesnames starting with two digit years (e.g. 11, 12) untouched.


$ ls -1
10th.Circuit
11th.Circuit
1st.Circuit
2nd.Circuit
3rd.Circuit
4th.Circuit
5th.Circuit
6th.Circuit
7th.Circuit
8th.Circuit
9th.Circuit
DC.Circuit


$ for old in $&#40;ls -1 &#124; grep &#34;^[0-9]\{1\}[a-z]&#34;&#41;; do rename -n 's//0/' $old; done
1st.Circuit renamed as 01st.Circuit
2nd.Circuit renamed as 02nd.Circuit
3rd.Circuit renamed as 03rd.Circuit
4th.Circuit renamed as 04th.Circuit
5th.Circuit [...]]]></description>
			<content:encoded><![CDATA[<p>Pad filenames starting with a single digit year (e.g. 1, 2, etc) with a zero while leaving filesnames starting with two digit years (e.g. 11, 12) untouched.</p>
<p><span id="more-97"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-1</span>
10th.Circuit
11th.Circuit
1st.Circuit
2nd.Circuit
3rd.Circuit
4th.Circuit
5th.Circuit
6th.Circuit
7th.Circuit
8th.Circuit
9th.Circuit
DC.Circuit</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">for</span> old <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^[0-9]\{1\}[a-z]&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> rename <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'s//0/'</span> <span style="color: #007800;">$old</span>; <span style="color: #000000; font-weight: bold;">done</span>
1st.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 01st.Circuit
2nd.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 02nd.Circuit
3rd.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 03rd.Circuit
4th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 04th.Circuit
5th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 05th.Circuit
6th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 06th.Circuit
7th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 07th.Circuit
8th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 08th.Circuit
9th.Circuit renamed <span style="color: #c20cb9; font-weight: bold;">as</span> 09th.Circuit</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-one-liner-to-pad-filenames-starting-with-single-digit-year-with-a-zero/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cron (logrotate) error rotating MySQL logs</title>
		<link>http://giantdorks.org/alain/cron-logrotate-error-rotating-mysql-logs/</link>
		<comments>http://giantdorks.org/alain/cron-logrotate-error-rotating-mysql-logs/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 16:24:53 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=108</guid>
		<description><![CDATA[Setup a new backup server and getting the following error from Cron in /etc/cron.daily/logrotate:

error: error running shared postrotate script for /var/log/mysql.log
/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log
run-parts: /etc/cron.daily/logrotate exited with return code 1


The problem was that I imported all DBs from the prod server, which had a different password for the debian-sys-maint user so the following test would fail:

# mysqladmin [...]]]></description>
			<content:encoded><![CDATA[<p>Setup a new backup server and getting the following error from Cron in /etc/cron.daily/logrotate:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">error: error running shared postrotate script for /var/log/mysql.log
/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log
run-parts: /etc/cron.daily/logrotate exited with return code 1</pre></div></div>

<p><span id="more-108"></span></p>
<p>The problem was that I imported all DBs from the prod server, which had a different password for the debian-sys-maint user so the following test would fail:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># mysqladmin --defaults-file=/etc/mysql/debian.cnf ping
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using
password: YES)'</pre></div></div>

<p>Easy fix is to copy the password from /etc/mysql/debian.cnf from the prod to the backup. Now this works:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># mysqladmin --defaults-file=/etc/mysql/debian.cnf ping
mysqld is alive</pre></div></div>

<p>&#8230; and MySQL logs are getting rotated again. </p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/cron-logrotate-error-rotating-mysql-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell one liner to rename files based on content</title>
		<link>http://giantdorks.org/alain/shell-one-liner-to-loop-through-files-parse-out-source-and-date-from-each-file-rearrange-date-construct-new-file-name-and-rename-each-file/</link>
		<comments>http://giantdorks.org/alain/shell-one-liner-to-loop-through-files-parse-out-source-and-date-from-each-file-rearrange-date-construct-new-file-name-and-rename-each-file/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 14:21:39 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Awk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=114</guid>
		<description><![CDATA[The shell one line script below will:
1. Find all files below current dir
2. Rename the file with download Source and date range as part of the new file name
3. Renamed file will stay at current location (e.g. file &#8220;./path/to/dir/crappyname&#8221; becomes &#8220;./path/to/dir/DC.Circuit-2006.06.02-2006.07.01.txt&#8221;)

Note: For it to work as expected, it should find a line that starts with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2007/12/wackpngn.jpg" alt="" align="left" />The shell one line script below will:</p>
<p>1. Find all files below current dir<br />
2. Rename the file with download Source and date range as part of the new file name<br />
3. Renamed file will stay at current location (e.g. file &#8220;./path/to/dir/crappyname&#8221; becomes &#8220;./path/to/dir/DC.Circuit-2006.06.02-2006.07.01.txt&#8221;)</p>
<p><span id="more-114"></span></p>
<p><strong>Note:</strong> For it to work as expected, it should find a line that starts with &#8220;Source:&#8221; and use first two words (e.g. &#8220;Source:DC Circuit &#8211; US Court of Appeals, District &amp; Bankruptcy Cases, &#8230;&#8221; becomes &#8220;DC.Circuit&#8221;). It should also find a line that starts with &#8220;SearchTerms:&#8221; out of which it&#8217;ll extract the date range (e.g. &#8220;SearchTerms: date(geq (06/02/2006) and leq (07/01/2006))&#8221; becomes &#8220;2006.06.02-2006.07.01).</p>
<p>Do a dry run and examine rename.test for errors. This works to verify the quality of download as well, as it should reveal date ranges of downloaded files and their source.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">dir</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$f</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">source</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-20</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Source:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$1&quot;.&quot;$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/ //g'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">dates</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-20</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^SearchTerms:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s_/_._g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)/\2.\1-\5.\4txt/'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\.-/-/'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> would rename <span style="color: #007800;">$f</span> to <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$source</span>-<span style="color: #007800;">$dates</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> would rename <span style="color: #007800;">$f</span> to dir<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$source</span>-<span style="color: #007800;">$dates</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> rename.test; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Examine output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> rename.test <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-dk4</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">less</span></pre></td></tr></table></div>

<p>Do the rename:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">dir</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$f</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">source</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-20</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Source:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$1&quot;.&quot;$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/ //g'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">dates</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-20</span> <span style="color: #007800;">$f</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^SearchTerms:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s_/_._g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)/\2.\1-\5.\4txt/'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\.-/-/'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> renaming <span style="color: #007800;">$f</span> to <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$source</span>-<span style="color: #007800;">$dates</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$f</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$source</span>-<span style="color: #007800;">$dates</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Test our SED by enclosing matches (back references) in parenthesis:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> 01.01.1910-12.31.1914- <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\([0-9]\{2\}.[0-9]\{2\}.\)\([0-9]\{4\}\)\(-\)\([0-9]\{2\}.[0-9]\{2\}.\)\([0-9]\{4\}\)\(-\)/(\1)(\2)(\3)(\4)(\5)(\6)/'</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>01.01.<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1910</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>12.31. <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1914</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
$ <span style="color: #7a0874; font-weight: bold;">echo</span> 01.01.1910-12.31.1914- <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)\([0-9]\{1,2\}.[0-9]\{1,2\}.\)\([0-9]\{4\}\)\(-\)/\2.\1-\5.\4txt/'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\.-/-/'</span>
1910.01.01-1914.12.31.txt</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-one-liner-to-loop-through-files-parse-out-source-and-date-from-each-file-rearrange-date-construct-new-file-name-and-rename-each-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shared folder permissions made easier with libpam-umask</title>
		<link>http://giantdorks.org/alain/shared-folder-permissions-made-easier-with-libpam-umask/</link>
		<comments>http://giantdorks.org/alain/shared-folder-permissions-made-easier-with-libpam-umask/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 16:52:33 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=123</guid>
		<description><![CDATA[With User Private Groups, umask of 002 or 007 makes more sense than the traditional umask of 022 when multiple users are working with shared files. Libpam-umask is handy for overriding the default umask setting.
Starting with Debian Lenny, libpam-umask is part of libpam-modules (which was auto installed on every Debian Lenny setup I&#8217;ve done so [...]]]></description>
			<content:encoded><![CDATA[<p>With User Private Groups, umask of 002 or 007 makes more sense than the traditional umask of 022 when multiple users are working with shared files. Libpam-umask is handy for overriding the default umask setting.</p>
<p>Starting with Debian Lenny, libpam-umask is part of libpam-modules (which was auto installed on every Debian Lenny setup I&#8217;ve done so far), so just need to add the following to &#8220;/etc/pam.d/common-session&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">session    optional     pam_umask.so umask=002</pre></div></div>

<p><span id="more-123"></span></p>
<p>Be sure to comment out conflicting umask directives elsewhere (e.g. /etc/profile).. </p>
<p>On Debian Etch, an addition step of installing libpam-modules is required:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># aptitude install libpam-umask</pre></div></div>

<p>Lots of good info on UPG from a RedHat <a href="http://www.redhat.com/docs/manuals/linux/RHL-7.1-Manual/ref-guide/s1-users-groups-private-groups.html">manual</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shared-folder-permissions-made-easier-with-libpam-umask/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to calculate clip duration from start/stop times for trimming with mencoder or ffmpeg</title>
		<link>http://giantdorks.org/alain/script-to-calculate-clip-duration-from-startstop-times/</link>
		<comments>http://giantdorks.org/alain/script-to-calculate-clip-duration-from-startstop-times/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 10:23:24 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=129</guid>
		<description><![CDATA[To trim a video clip, mencoder and ffmpeg expect a start time in hh:mm:ss, but instead of end time, want duration:

$ mencoder -ss 00:02:55 -endpos 00:07:15 -oac copy -ovc copy in.avi -o out.avi
$ ffmpeg -ss 00:02:55 -t 00:07:15 -vcodec copy -acodec copy -i in.avi out.avi

Video players make it easy to identify start/stop times, but difficult [...]]]></description>
			<content:encoded><![CDATA[<p>To trim a video clip, mencoder and ffmpeg expect a start time in hh:mm:ss, but instead of end time, want duration:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mencoder -ss 00:02:55 -endpos 00:07:15 -oac copy -ovc copy in.avi -o out.avi
$ ffmpeg -ss 00:02:55 -t 00:07:15 -vcodec copy -acodec copy -i in.avi out.avi</pre></div></div>

<p>Video players make it easy to identify start/stop times, but difficult to figure out duration, so I wrote a little shell script that will calculate duration from start/stop times.</p>
<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ calc-duration 00:02:<span style="color: #000000;">55</span> 00:<span style="color: #000000;">10</span>:<span style="color: #000000;">10</span>
&nbsp;
 Start: 00 hrs 02 min <span style="color: #000000;">55</span> sec
 Stop:  00 hrs <span style="color: #000000;">10</span> min <span style="color: #000000;">10</span> sec
&nbsp;
 +----------------------+
 <span style="color: #000000; font-weight: bold;">|</span> duration is 00:07:<span style="color: #000000;">15</span> <span style="color: #000000; font-weight: bold;">|</span>
 +----------------------+</pre></div></div>

<p><span id="more-129"></span></p>
<p>Script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#============================================================#</span>
<span style="color: #666666; font-style: italic;"># Calculates duration between start time and stop time</span>
<span style="color: #666666; font-style: italic;"># USAGE: calc-duration 00:02:00 00:10:10</span>
<span style="color: #666666; font-style: italic;"># Fix:</span>
<span style="color: #666666; font-style: italic;"># 1. Currently expects start hour to be less than stop hour,</span>
<span style="color: #666666; font-style: italic;"># so won't work for a clip that's longer than 24 hrs, not an</span>
<span style="color: #666666; font-style: italic;"># issue for me as I don't have any of those... ;-)</span>
<span style="color: #666666; font-style: italic;">#============================================================#</span>
<span style="color: #007800;">starthh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">startmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">startss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$3}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #007800;">stophh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">stopmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">stopss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$3}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Start:&quot;</span> <span style="color: #007800;">$starthh</span> hrs <span style="color: #007800;">$startmm</span> min <span style="color: #007800;">$startss</span> sec
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Stop: &quot;</span> <span style="color: #007800;">$stophh</span> hrs <span style="color: #007800;">$stopmm</span> min <span style="color: #007800;">$stopss</span> sec
<span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span>   <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$startmm)) -gt $((10#$stopmm)) &amp;&amp; $((10#$startss)) -gt $((10#$stopss)) ]]; then</span>
        <span style="color: #666666; font-style: italic;"># echo start mm and ss are greater than stop</span>
	<span style="color: #666666; font-style: italic;"># start mm is greater than stop mm, so we add 60 to stop mm and</span>
	<span style="color: #666666; font-style: italic;"># substract 1 from stop hh</span>
	<span style="color: #007800;">newstopmm1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopmm+10#60))</span>
	<span style="color: #007800;">newstophh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stophh-10#1))</span>
	<span style="color: #666666; font-style: italic;"># start ss is greater than stop ss, so we add 60 to stop ss and</span>
        <span style="color: #666666; font-style: italic;"># substract 1 from stop mm</span>
        <span style="color: #007800;">newstopss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopss+10#60))</span>
        <span style="color: #007800;">newstopmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopmm1-10#1))</span>
        <span style="color: #666666; font-style: italic;"># calculate differences</span>
	<span style="color: #007800;">diffhh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstophh-10#$starthh))</span>
	<span style="color: #007800;">diffmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopmm-10#$startmm))</span>
	<span style="color: #007800;">diffss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopss-10#$startss))</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$startmm)) -gt $((10#$stopmm)) ]]; then</span>
        <span style="color: #666666; font-style: italic;"># echo startmm is greater than stopmm</span>
	<span style="color: #666666; font-style: italic;"># start mm is greater than stop mm, so we add 60 to stop mm and</span>
        <span style="color: #666666; font-style: italic;"># substract 1 from stop hh</span>
        <span style="color: #007800;">newstopmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopmm+10#60))</span>
        <span style="color: #007800;">newstophh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stophh-10#1))</span>
	<span style="color: #666666; font-style: italic;"># calculate differences</span>
        <span style="color: #007800;">diffhh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstophh-10#$starthh))</span>
        <span style="color: #007800;">diffmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopmm-10#$startmm))</span>
        <span style="color: #007800;">diffss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopss-10#$startss))</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$startss)) -gt $((10#$stopss)) ]]; then</span>
        <span style="color: #666666; font-style: italic;"># echo startss is greater than stopss</span>
        <span style="color: #666666; font-style: italic;"># start ss is greater than stop ss, so we add 60 to stop ss and</span>
        <span style="color: #666666; font-style: italic;"># substract 1 from stop mm</span>
        <span style="color: #007800;">newstopss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopss+10#60))</span>
        <span style="color: #007800;">newstopmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopmm-10#1))</span>
        <span style="color: #666666; font-style: italic;"># calculate differences</span>
        <span style="color: #007800;">diffhh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stophh-10#$starthh))</span>
        <span style="color: #007800;">diffmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopmm-10#$startmm))</span>
        <span style="color: #007800;">diffss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$newstopss-10#$startss))</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #666666; font-style: italic;"># echo all stop values are greater than start values</span>
        <span style="color: #666666; font-style: italic;"># calculate differences</span>
        <span style="color: #007800;">diffhh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stophh-10#$starthh))</span>
        <span style="color: #007800;">diffmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopmm-10#$startmm))</span>
        <span style="color: #007800;">diffss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #666666; font-style: italic;">#$stopss-10#$startss))</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pad single digit results with a zero (if + signs contain a single digit, add a zero, then remove + signs)</span>
<span style="color: #007800;">pdiffhh</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> +<span style="color: #007800;">$diffhh</span>+ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/+\([0-9]\{1\}\)+/+0\1+/g;s/+//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">pdiffmm</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> +<span style="color: #007800;">$diffmm</span>+ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/+\([0-9]\{1\}\)+/+0\1+/g;s/+//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">pdiffss</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> +<span style="color: #007800;">$diffss</span>+ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/+\([0-9]\{1\}\)+/+0\1+/g;s/+//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; +----------------------+&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; | duration is&quot;</span> <span style="color: #007800;">$pdiffhh</span>:<span style="color: #007800;">$pdiffmm</span>:<span style="color: #007800;">$pdiffss</span> <span style="color: #ff0000;">&quot;|&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; +----------------------+&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/script-to-calculate-clip-duration-from-startstop-times/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sed one liners to display line ranges</title>
		<link>http://giantdorks.org/alain/sed-one-liners-to-display-line-ranges/</link>
		<comments>http://giantdorks.org/alain/sed-one-liners-to-display-line-ranges/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 08:02:22 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Script]]></category>
		<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=147</guid>
		<description><![CDATA[Display all lines from file except lines between two lines matching a pattern:

1
sed '/10\/02\/1992/,/01\/02\/2001/d' input.txt

Display lines between two lines matching a pattern:

1
sed -n '/10\/02\/1992/,/01\/02\/2001/p' input.txt


Display all lines from file, excluding a line range between 2 and 90:

1
sed 2,90d input.txt

Display only lines between line numbers 2 and 90:

1
sed -n 2,90p input.txt

Display line two:

1
sed -n 2p input.txt

]]></description>
			<content:encoded><![CDATA[<p>Display all lines from file except lines between two lines matching a pattern:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'/10\/02\/1992/,/01\/02\/2001/d'</span> input.txt</pre></td></tr></table></div>

<p>Display lines between two lines matching a pattern:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'/10\/02\/1992/,/01\/02\/2001/p'</span> input.txt</pre></td></tr></table></div>

<p><span id="more-147"></span></p>
<p>Display all lines from file, excluding a line range between 2 and 90:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #000000;">2</span>,90d input.txt</pre></td></tr></table></div>

<p>Display only lines between line numbers 2 and 90:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">2</span>,90p input.txt</pre></td></tr></table></div>

<p>Display line two:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> 2p input.txt</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/sed-one-liners-to-display-line-ranges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell one liner to convert DHCP reservation values from Vyatta config into a Bind zone file format</title>
		<link>http://giantdorks.org/alain/shell-one-liner-to-convert-dhcp-reservation-values-from-vyatta-config-into-a-bind-zone-file-format/</link>
		<comments>http://giantdorks.org/alain/shell-one-liner-to-convert-dhcp-reservation-values-from-vyatta-config-into-a-bind-zone-file-format/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 07:55:56 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Bind]]></category>
		<category><![CDATA[Vyatta]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=144</guid>
		<description><![CDATA[DHCP reservations in the Vyatta config.boot are in the following format:

   ---------------8&#60;---------------
       static-mapping HOST1 {
           ip-address 192.168.1.91
           mac-address aa:12:34:45:67:89
       }
  [...]]]></description>
			<content:encoded><![CDATA[<p>DHCP reservations in the Vyatta config.boot are in the following format:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">   ---------------8&lt;---------------
       static-mapping HOST1 {
           ip-address 192.168.1.91
           mac-address aa:12:34:45:67:89
       }
       static-mapping HOST2 {
           ip-address 192.168.1.92
           mac-address bb:12:34:45:67:89
       }
       static-mapping HOST3 {
           ip-address 192.168.1.93
           mac-address cc:12:34:45:67:89
   ---------------8&lt;---------------</pre></div></div>

<p><span id="more-144"></span></p>
<p>The following shell one line script will convert the above into a format suitable for inclusion in a Bind DNS zone file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-A1</span> static-mapping config.boot <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff0000;">&quot; &quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/\1\n/g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print$2 &quot;\t&quot; $1}'</span>
192.168.1.91    HOST1
192.168.1.92    HOST2
192.168.1.93    HOST3</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/shell-one-liner-to-convert-dhcp-reservation-values-from-vyatta-config-into-a-bind-zone-file-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error &#8220;rfcomm connection refused&#8221; attempting to establish a GPRS modem connection over a Bluetooth phone</title>
		<link>http://giantdorks.org/alain/error-rfcomm-connection-refused-attempting-to-establish-a-gprs-modem-connection-over-a-bluetooth-phone/</link>
		<comments>http://giantdorks.org/alain/error-rfcomm-connection-refused-attempting-to-establish-a-gprs-modem-connection-over-a-bluetooth-phone/#comments</comments>
		<pubDate>Fri, 01 May 2009 21:22:32 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Phones]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=80</guid>
		<description><![CDATA[This had been working without any problems for months, but this afternoon got an error while trying to connect to the Internet using my Nokia E62 as a Bluetooth modem on a Dell Inspiron E1505 running Ubuntu 8.10. Attempting to establish a dial up connection returned a rude error.


# wvdial E62
rfcomm connection refused

The solution was [...]]]></description>
			<content:encoded><![CDATA[<p>This had been working without any problems for months, but this afternoon got an error while trying to connect to the Internet using my Nokia E62 as a Bluetooth modem on a Dell Inspiron E1505 running Ubuntu 8.10. Attempting to establish a dial up connection returned a rude error.</p>
<p><span id="more-80"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># wvdial E62
rfcomm connection refused</pre></div></div>

<p>The solution was to remove the file containing the Link Keys used for the Bluetooth challenge-response scheme and letting the system recreate it after a successful bind. On my system this file was named &#8220;linkkeys&#8221; and lived in /var/lib/bluetooth/[device MAC address]</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>bluetooth<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> linkkeys <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">rm</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/error-rfcomm-connection-refused-attempting-to-establish-a-gprs-modem-connection-over-a-bluetooth-phone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Sniffing packets for fun and profit</title>
		<link>http://giantdorks.org/alain/quick-tip-sniffing-packets-for-fun-and-profit/</link>
		<comments>http://giantdorks.org/alain/quick-tip-sniffing-packets-for-fun-and-profit/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 20:40:39 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Network]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/quick-tip-sniffing-packets-for-fun-and-profit/</guid>
		<description><![CDATA[When it comes to analyzing network problems, debugging client / server communication or just monitoring network traffic, a protocol analyzer (packet sniffer) is king.]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2008/01/w1reshark.gif" alt="w1reshark.gif" align="left" />When it comes to analyzing network problems, debugging client / server communication or just monitoring network traffic, a protocol analyzer (packet sniffer) is king.</p>
<p>There are a number of packet sniffers out there, two of the most popular are Wireshark (formerly Ethereal) and tcpdump. Tshark is the console (command line) version of Wireshark.</p>
<p><span id="more-42"></span></p>
<p>Running a packet sniffer on even a moderately busy network will produce a ton of output so use of filters is a must. Since both Wireshark (tshark) and tcpdump use the pcap library (libpcap on UNIX and winpcap on Windows), they both use the same filter syntax.</p>
<p>There are lots of filter options. Filters can be combined with logical operators &#8220;and&#8221;, &#8220;not&#8221; and &#8220;or&#8221;.</p>
<p>Basic example below will capture DNS (port 53) traffic going to and from host 192.168.1.5:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">tshark <span style="color: #660033;">-i</span> eth1 port <span style="color: #000000;">53</span> and host 192.168.1.5</pre></td></tr></table></div>

<p>When using multiple logical operators, filter syntax can get confusing. Parenthesis can be used to group multiple filter statements to make them easier on the eye.</p>
<p>A more complex filter example below will capture all traffic to/from hosts 192.168.1.4 and 192.168.1.5 except HTTP (port 80) and SMTP (port 25):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">tshark <span style="color: #660033;">-i</span> eth1 <span style="color: #ff0000;">'(host 192.168.1.4 or host 192.168.1.5) and not (port 80 or port 25)'</span></pre></td></tr></table></div>

<p>Please note that if I didn&#8217;t enclose the filter statement above in quotes, the shell would have tried to evaluate the parenthesis, returning an error similar to:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">-sh: syntax error near unexpected token `('</pre></div></div>

<p>Enclosing the filter statement in quotes tells the shell to just pass the arguments along without evaluating.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/quick-tip-sniffing-packets-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Installing bleeding edge packages on Debian stable</title>
		<link>http://giantdorks.org/alain/quick-tip-installing-bleeding-edge-packages-on-debian-stable/</link>
		<comments>http://giantdorks.org/alain/quick-tip-installing-bleeding-edge-packages-on-debian-stable/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 18:25:59 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[APT]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/quick-tip-installing-bleeding-edge-packages-on-debian-stable/</guid>
		<description><![CDATA[For a server, I prefer to run the latest stable release of Debian, but once in a while I need a newer package than what's available from with the stable repository. Here's how to keep a mixed Debian system.]]></description>
			<content:encoded><![CDATA[<p>For a server, I prefer to run the latest stable release of Debian, but once in a while I need a newer package than what&#8217;s available from the stable repository.</p>
<p>The solution is in the Apt How-To available from Debian. See section 3.8, title &#8220;<a href="http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html#s-default-version">How to keep a mixed system</a>&#8220;.</p>
<p><span id="more-39"></span></p>
<p>First, a word of warning. APT is great but will dutifully do as you say, so you could get yourself into trouble. Mix packages from different releases with caution. When a package has lots of dependencies, often a newer version of a prerequisite package is listed, so to upgrade a single package to the testing version, APT might have to upgrade a number of other packages as well. This may become problematic. APT will warn you before doing anything, so consider those carefully. Personally, I don&#8217;t have a hard rule for mixing packages. Sometimes it makes sense to mix, sometimes it makes more sense to just setup a dedicated box or a VM to run Debian Testing/Unstable.</p>
<blockquote><p>
IMPORTANT: the &#8220;unstable&#8221; version of Debian is the version to which the newest versions of Debian packages are uploaded first. This distribution sees all of the changes that packages go through, both small ones and more drastic ones which affect many packages or the whole system. For this reason, this version of the distribution should not be used by inexperienced users or by those who need proven stability.<br />
The &#8216;testing&#8217; distribution is not necessarily better than &#8216;unstable&#8217;, because it does not receive security updates quickly. For servers and other production systems stable should always be used.
</p></blockquote>
<p>Here are the steps (this example is for getting the latest Bind9 package):</p>
<p>1. Edit /etc/apt/sources.list and add testing package source repository  to your source list</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># testing
deb http://ftp.us.debian.org/debian/ testing main contrib non-free
deb-src http://ftp.us.debian.org/debian/ testing main contrib non-free
&nbsp;
# testing security
deb http://security.debian.org testing/updates main contrib non-free
deb-src http://security.debian.org testing/updates main contrib non-free</pre></div></div>

<p>2. Create /etc/apt/apt.conf and add:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">APT::Default-Release &quot;stable&quot;;
APT::Cache-Limit &quot;25165824&quot;;</pre></div></div>

<p>This will tell apt not to automagically upgrade all your packages (essentially &#8220;upgrading&#8221; your entire system to the testing or unstable release) and also raise the cache limits as the default cache value is probably too small to accomodate this new larger set of packages.</p>
<p>3. Create /etc/apt/preferences and add:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Package: *
Pin: release a=stable
Pin-Priority: 990
&nbsp;
Package: *
Pin: release a=testing
Pin-Priority: 450</pre></div></div>

<p>This will tell apt to default to a stable version of a package, rather than to a higher release.</p>
<p>4. Update apt</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">aptitude update</pre></div></div>

<p>5. Probably the easiest way to check what versions of Bind9 available from the repositories is to search packages.debian.org:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">links2 http://packages.debian.org/bind9</pre></div></div>

<p>6. Install Bind9 from the testing repository</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">aptitude -t testing install bind9</pre></div></div>

<p>That&#8217;s it. Debian&#8217;s advanced package management system is one more reason I love it more every day. <img src='http://giantdorks.org/alain/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/quick-tip-installing-bleeding-edge-packages-on-debian-stable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux bandwidth monitoring and network accounting tools</title>
		<link>http://giantdorks.org/alain/linux-bandwidth-monitoring-and-network-accounting-tools/</link>
		<comments>http://giantdorks.org/alain/linux-bandwidth-monitoring-and-network-accounting-tools/#comments</comments>
		<pubDate>Tue, 25 Dec 2007 00:58:08 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/linux-bandwidth-monitoring-and-network-accounting-tools/</guid>
		<description><![CDATA[Some time ago I was looking for tools to monitor network bandwidth usage by clients. Needed something to run on my super awesome Linux router/firewall (Vyatta) to see what everyone on the network is doing and on the Xen VM hosts to keep an eye on the virtual machines. Here's what I found...]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2007/12/s1a1s.gif" align="left" />Some time ago I was looking for tools to monitor network bandwidth usage by clients. Needed something to run on my super awesome Linux router/firewall (<a title="Vyatta - Welcome to the Dawn of Open-Source Networking" href="http://www.vyatta.com/">Vyatta</a>) to see what everyone on the network is doing and on the Xen VM hosts to keep an eye on the virtual machines.</p>
<p>As always with Linux, there are lots of quality projects worth serious consideration, so the hardest part was to narrow the plethora of choices down to a manageable number to test.</p>
<p><span id="more-33"></span></p>
<p>Specific requirements were:</p>
<ul>
<li>Runs on Linux</li>
<li>Keeps historical data</li>
<li>Not a resource hog (RAM, CPU or Disk)</li>
<li>Keeps data in a format easily queried by other tools</li>
<li>Released under an Open Source license</li>
</ul>
<p>Out of the various tools I&#8217;ve tried, <a title="Linux network accounting tool" href="http://freshmeat.net/projects/nacctsql/">Netacct-mysql</a> is currently my favorite.  It collects bandwidth data through libpcap and stores in a MySQL database (reportedly, PostgreSQL and Oracle are also supported).  It comes with a dedicated PHP front end, but to me the real power is that it stores the stats in the database, so through SQL SELECT statements, I&#8217;m able to get all the stats I need.</p>
<p>I was thinking about taking it a step further and getting some pretty graphs out of the data. <a title="Matt Dunlap is a GIANT dork." href="http://mattdunlap.org/">Matt Dunlap</a>, had suggested taking a look at <a title="PHP/SWF Charts" href="http://www.maani.us/charts/index.php">PHP/SWF Charts</a>.. Looks promising and it&#8217;s on my to do list.</p>
<p>Meanwhile, here are the installation steps for Netacct-mysql on Vyatta. Steps apply to Debian as well, since Vyatta is based on Debian (if you believe /etc/debian_version, which, on both Vyatta VC2 and VC3, reports &#8220;Debian 4.0&#8243;, aka &#8220;Etch&#8221;):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server libpcap-dev <span style="color: #c20cb9; font-weight: bold;">gcc</span> libmysqlclient15-dev <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>netacct-mysql.gabrovo.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>netacct-mysql-0.78.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvfz netacct-mysql-0.78.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> netacct-mysql-<span style="color: #000000;">0.78</span>
mysql <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">&lt;</span> netacct.sql
mysqladmin <span style="color: #660033;">-u</span> root password yourpasshere
mysql <span style="color: #660033;">-u</span> root <span style="color: #660033;">-p</span> yourpasshere</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> netacct<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'acct'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'somepass'</span>;
<span style="color: #993333; font-weight: bold;">FLUSH</span> PRIVILEGES;
quit</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>netacct-mysql-<span style="color: #000000;">0.78</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Edit nacct config files and define your options (e.g. enter the MySQL pass for user acct, define your network adapters and your networks)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>naccttab
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nacctpeering
<span style="color: #c20cb9; font-weight: bold;">cp</span> contrib<span style="color: #000000; font-weight: bold;">/</span>nacctd.debian <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nacctd
update-rc.d nacctd defaults
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nacctd start
<span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> nacctd <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span></pre></td></tr></table></div>

<p>All done. Give the nacctd daemon about an hour (it keeps hourly stats) and you should start seeing numbers in your DB. Let&#8217;s see some stats!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">mysql <span style="color: #66cc66;">-</span>u root <span style="color: #66cc66;">-</span>p
<span style="color: #993333; font-weight: bold;">USE</span> netacct;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> traffic;
&nbsp;
<span style="color: #808080; font-style: italic;"># Get total (in+out, in GBs) bandwidth used by 10.2.28.122 during Dec 07</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> SUM<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>input<span style="color: #66cc66;">+</span>output<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1073741824</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> traffic <span style="color: #993333; font-weight: bold;">WHERE</span> IP<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'10.2.28.122'</span> <span style="color: #993333; font-weight: bold;">AND</span> time <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'2007-12%'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Get (in &amp; out, in GBs) bandwidth used by all hosts during Dec 07</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> traffic<span style="color: #66cc66;">.</span>ip<span style="color: #66cc66;">,</span> sum<span style="color: #66cc66;">&#40;</span>input<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1073741824</span> inp<span style="color: #66cc66;">,</span> sum<span style="color: #66cc66;">&#40;</span>output<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1073741824</span> outp <span style="color: #993333; font-weight: bold;">FROM</span> traffic <span style="color: #993333; font-weight: bold;">WHERE</span> time <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'2007-12%'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> ip;</pre></td></tr></table></div>

<p>Hope you&#8217;re getting nice stats and that warm fuzzy feeling which comes with a false sense of security. For some additional info, check out the <a title="Netacct-mysql project page" href="http://netacct-mysql.gabrovo.com/">Netacct-mysql project page</a>. Also, take a look at this post on <a title="Monitoring Bandwidth Usage for a Xen node" href="http://www.ioncannon.net/system-administration/84/monitoring-bandwidth-usage-for-a-xen-node/">Monitoring Bandwidth Usage for a Xen node</a>, which is where I first learned about Netacct-mysql.</p>
<p>In addition to Netacct-mysql, I frequently use a couple of other tools also. Check them out!</p>
<ol>
<li><a title="Bmon - Portable bandwidth monitor and rate estimator" href="http://people.suug.ch/~tgr/bmon/"><strong>Bmon</strong></a><br />
<a title="bm0n.gif" href="http://giantdorks.org/alain/files/2007/12/bm0n.gif"><img src="http://giantdorks.org/alain/files/2007/12/bm0n-150x150.gif" alt="bm0n.gif" align="left" /></a>I use this one for real time bandwidth monitoring at the console. Bmon tracks usage by interface. Looks great for a console tool. Description of the tool from the project page: <span style="color: #0000ff"><em>&#8220;bmon is a portable bandwidth monitor and rate estimator running on various operating systems. It supports various input methods for different architectures. Various output modes exist including an interactive curses interface, lightweight HTML output but also formatable ASCII output.&#8221;</em></span></li>
<li><a title="vnStat - a network traffic monitor" href="http://humdi.net/vnstat/"><strong>Vnstat</strong></a><br />
<a title="vns1a1.gif" href="http://giantdorks.org/alain/files/2007/12/vns1a1.gif"><img src="http://giantdorks.org/alain/files/2007/12/vns1a1-150x150.gif" alt="vns1a1.gif" align="left" /></a> Provides a historical view of bandwidth usage. Also tracks usage by interface. I use this one when I want a general overview of bandwidth usage, particularly on the edge router to see how close I am to overage charges from my colocation provider. The tool comes with a number of pre-configured display options (e.g. hours, days, weeks, months, top10). Can also measure and report back usage for a specified period time (e.g. 60 seconds). Description of the tool from the project page:<em> <span style="color: #0000ff">&#8220;vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s). vnStat isn&#8217;t a packet sniffer. The traffic information is analyzed from the /proc filesystem. That way vnStat can be used even without root permissions. However, at least a 2.2 series kernel is required.&#8221;</span></em></li>
</ol>
<p>Well, that&#8217;s it. If you have some pointers, please leave a comment! Happy <a title="a Festivus for the rest of us!" href="http://en.wikipedia.org/wiki/Festivus">Festivus</a> to all!</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/linux-bandwidth-monitoring-and-network-accounting-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing services in Debian</title>
		<link>http://giantdorks.org/alain/managing-services-in-debian/</link>
		<comments>http://giantdorks.org/alain/managing-services-in-debian/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 02:31:19 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/managing-services-in-debian/</guid>
		<description><![CDATA[When it comes to managing services, I'm used to System V style commands used in Red Hat / Fedora (and derivatives) as well as SUSE, so I found Debian service management methods unintuitive at first. Here are some personal notes I made to help myself out...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m used to System V style commands used in Red Hat / Fedora and derivatives as well as SUSE, so I found Debian service management methods unintuitive at first.</p>
<p>Below are a couple of personal notes I made on the subject to help myself out, as I was getting used to the Debian way of things&#8230;</p>
<p><span id="more-26"></span>List existing services:<br />
<code><br />
<font color="#ffcc00"> ls /etc/rc2.d/S*</font></code></p>
<p>Manage services [start,stop,reload,etc]:<br />
<code><br />
<font color="#ffcc00"> /etc/init.d/</font><font color="#999999"><em>service command</em></font></code></p>
<p>Make service start on boot:<br />
<code><br />
<font color="#ffcc00"> update-rc.d </font><em><font color="#999999">name </font></em><font color="#ffcc00">defaults</font></code></p>
<p>The &#8216;defaults&#8217; value makes the service start in runlevels 0123 and stop in 456. Alternatively, you can specify which runlevels the service will start and stop in with:<br />
<code><br />
<font color="#ffcc00"> update-rc.d</font> <font color="#c0c0c0"><em>name</em> </font><font color="#ffcc00">start</font> <font color="#c0c0c0"><em>runlevel</em></font> <font color="#ffcc00">stop</font> <em><font color="#c0c0c0">runlevel</font></em></code></p>
<p>To remove service from starting on boot:<br />
<code><br />
<font color="#ffcc00"> update-rc.d</font> <em><font color="#c0c0c0">name </font></em><font color="#ffcc00">remove</font></code></p>
<p>BTW, for a really excellent breakdown of update-rc.d options, check out this <a href="http://www.debuntu.org/how-to-manage-services-with-update-rc.d" title="Managing services with update-rc.d in Debian">well written post</a>.</p>
<p>If you install sysvconfig (apt-get install sysvconfig) you can also use System V style commands to start/stop services:<br />
<code><br />
<font color="#ffcc00"> service <font color="#c0c0c0"><em>name command</em></font></font></code></p>
<p>Unfortunately, even having installed sysvconfig in Debian, the command to list all services with status (e.g. running, unused, etc) is still missing. In SUSE, you&#8217;d run it with:</p>
<p><code><font color="#ffcc00"><br />
service -s</font></code></p>
<p>And would get a nice little list like this:</p>
<p><img src="http://giantdorks.org/alain/files/2007/12/serv1ce-s.png" alt="serv1ce-s.png" /></p>
<p>In the absence of the above, you could just list running processes with &#8216;ps&#8217;.. Another option is to list files in /var/run whose filename ends with &#8216;pid&#8217;, as each of those corresponds to a service:</p>
<p><code><br />
<font color="#ffcc00"> find . /var/run | grep pid</font></code></p>
<p>Yet another option, with sysvconfig installed on Debian, is to just run:</p>
<p><code><br />
<font color="#ffcc00"> sysvconfig</font></code></p>
<p>&#8230;which produces a clean and simple ncurses GUI which allows to manage service startup and edit runlevels:</p>
<p><img src="http://giantdorks.org/alain/files/2007/12/sysvc0nfig.gif" alt="sysvc0nfig.gif" /></p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/managing-services-in-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Add automatic syntax highlighting to custom file types in VIM</title>
		<link>http://giantdorks.org/alain/quick-tip-add-automatic-syntax-highlighting-to-custom-file-types-in-vim/</link>
		<comments>http://giantdorks.org/alain/quick-tip-add-automatic-syntax-highlighting-to-custom-file-types-in-vim/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 01:59:29 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/quick-tip-add-automatic-syntax-highlighting-to-custom-file-types-in-vim/</guid>
		<description><![CDATA[VIM is an awesome text editor and syntax highlighting is one of its many awesome features. While VIM will automagically highlight syntax for most common files, you might run into a situation where you're working with a file VIM won't automagically highlight. Here's how to enable syntax highlight for custom files.]]></description>
			<content:encoded><![CDATA[<p align="left"><a href="http://en.wikipedia.org/wiki/Vim_%28text_editor%29" title="VIM the text editor"><img src="http://giantdorks.org/alain/files/2007/12/v1m.png" alt="v1m.png" align="left" />VIM</a> is an awesome text editor and syntax highlighting is one of its many awesome features. To enable VIM syntax highlighting globally for all users, simply uncomment &#8220;Syntax on&#8221; in the VIM config file (which is typically /etc/vimrc). So long as your VIM version supports syntax highlighting, VIM will automagically highlight syntax for most common files. That&#8217;s great, but sometimes you might run into a situation where you&#8217;re working with a file VIM won&#8217;t automagically highlight syntax for. Let&#8217;s say you really, really would like it to. Here&#8217;s how&#8230;.</p>
<p align="left"><span id="more-19"></span></p>
<p>The example I&#8217;m using here is the Vyatta config file (BTW, not to digress, but <a href="http://www.vyatta.com" title="Vyatta, the Open Flexible Router">Vyatta</a> is a super awesome, flexible and capable Open Source router/firewall solution that runs on commodity x86 hardware). Anyway, by default, VIM doesn&#8217;t automatically syntax highlight the vyatta config file, config.boot. You can always enable it manually every time you open the file, by typing something like:</p>
<p><code><br />
<font color="#ffcc00"> :set syntax=perl</font><br />
</code></p>
<p>&#8230;but that gets old quick and so I&#8217;m going to setup VIM to automatically highlight the syntax for this file.</p>
<p>First, make sure your VIM version supports syntax highlight by turning it on manually. If VIM complains, you probably just need to update to the latest version (using whatever software update facility is appropriate for your Linux distribution).</p>
<p>Secondly, create two files in your home directory:</p>
<p><code><br />
<font color="#ffcc00"> cd ~<br />
touch .vimrc<br />
touch .vimcustomfiletypes</font><br />
</code></p>
<p>edit .vimrc and add:</p>
<p><code><br />
"turn on syntax highlighting<br />
<font color="#ffcc00"> syntax on</font><br />
"load your custom syntax highlight filetypes file<br />
<font color="#ffcc00"> so ~/.vimcustomfiletypes</font><br />
</code></p>
<p>edit .vimcustomfiletypes and add:</p>
<p><code><br />
<font color="#ffcc00"> augroup filetype<br />
au!<br />
au! BufRead,BufNewFile *.boot*    set filetype=cpp<br />
augroup END</font><br />
</code></p>
<p>The above will use &#8220;cpp&#8221; (e.g. C++) syntax highlight rules for files which contain &#8220;.boot&#8221; in the filename (like Vyatta&#8217;s config.boot). There are other ways to identify the file besides the file name, just take a look at the VIM documentation. Also, if none of the provided syntax highlight rule sets work for you, you could define your own. I haven&#8217;t had the need to do that (yet?).</p>
<p>So, next time we open the Vyatta config.boot file, instead of boring &#8216;ol this:</p>
<p><img src="http://giantdorks.org/alain/files/2007/12/no-highlight.gif" alt="no hightlight" /></p>
<p>We get this:</p>
<p><img src="http://giantdorks.org/alain/files/2007/12/highlight.gif" alt="with highlight" /></p>
<p>And what&#8217;s not to love about that?</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/quick-tip-add-automatic-syntax-highlighting-to-custom-file-types-in-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Disable the awful system beep in Ubuntu (and other Linux distros)</title>
		<link>http://giantdorks.org/alain/quick-tip-turn-off-the-annoying-system-beep-in-ubuntu/</link>
		<comments>http://giantdorks.org/alain/quick-tip-turn-off-the-annoying-system-beep-in-ubuntu/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 03:49:50 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/quick-tip-turn-off-the-annoying-system-beep-in-ubuntu/</guid>
		<description><![CDATA[So you installed a shiny new version of Ubuntu and are having a time of your life. That is until your machine shrieks with a beep that will shake your soul to the depths of its core. Here's a quick tip on how to get rid of it and live happily once again.]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2007/12/ubun7u_vect0rized.png" align="left" />So you installed a shiny new version of Ubuntu and are having a time of your life. That is until your machine shrieks with a horribly offensive beep you hadn&#8217;t heard since 1998. It would blast me out of my chair (and send the dog scurrying for the closet) every time I would hit the backspace key at the console and reach the beginning of the line. It took about four of those beeps before ridding myself of it became a priority.</p>
<p>As with most things in Linux, there are a million different ways of accomplishing the task. Here&#8217;s the ultra super easy method I like.</p>
<p><span id="more-17"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span># disable bell<span style="color: #000099; font-weight: bold;">\n</span>xset -b&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></td></tr></table></div>

<p>Sweet Jeesus, that was easy. This method should work for other Linux distributions as well. I haven&#8217;t tested it though since Ubuntu is the only desktop/laptop Linux I&#8217;m currently running.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/quick-tip-turn-off-the-annoying-system-beep-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to print an 8.5 x 3.5 check in QuickBooks</title>
		<link>http://giantdorks.org/alain/how-to-print-an-85-x-35-check-in-quickbooks/</link>
		<comments>http://giantdorks.org/alain/how-to-print-an-85-x-35-check-in-quickbooks/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 00:48:36 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Quickbooks]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/how-to-print-an-85-x-35-check-in-quickbooks/</guid>
		<description><![CDATA[So you got a great deal on some checks from an online vendor, however,
each 8.5" x 11" sheet contains three checks and QuickBooks will only
print the top one. No worries, the fix is easy!]]></description>
			<content:encoded><![CDATA[<p>This exciting post discusses how to print an individual 8.5&#8243; x 3.5&#8243; check in QuickBooks. I have found QuickBooks to be unintuitive and irritating. One of these days I will spend some time and identify and awesome Open Source alternative. In the meantime, here&#8217;s a big post on how to do a small task.</p>
<p>Alright, here it goes.. Let&#8217;s say you got a great deal on some checks from an online vendor, however, each 8.5&#8243; x 11&#8243; sheet contains three checks and QuickBooks will only print the top one. What a waste! Fortunately, there&#8217;s a way..</p>
<p><span id="more-13"></span></p>
<p><strong>Requirements:</strong></p>
<ul>
<li>QuickBooks software (tested Quickbooks Premier Professional Services Edition 2006)</li>
<li>Printer (tested HP LaserJet 4000)</li>
<li>Checks (tested Business Size, 3-Per-Page Computer Checks Without Lines, Form # 59011)</li>
</ul>
<ol>
<li>Separate the individual checks along the perforated lines.  Load a single check in your printer&#8217;s envelope tray and adjust plastic tray guides to the width of the check. Note: if the check has a Tear-Off Strip, remove it (typically the last check on the three page sheet would have the Tear-Off Strip)</li>
<li>In QuickBooks, go to print a check and
<ul>
<li>Under the &#8220;Settings&#8221; tab, choose Printer type: &#8220;Page-oriented (Single sheets)&#8221;</li>
<li>Under the &#8220;Settings&#8221; tab, set &#8220;Checks on 1st Page&#8221; to 1</li>
<li>Under the &#8220;Partial Page&#8221; tab, set &#8220;Partial Page Printing Style&#8221; to &#8220;Center&#8221;</li>
<li>Hit &#8220;Print&#8221; and answer &#8220;No&#8221; to the question about the Tear-Off Strip (which you removed in Step 1)</li>
</ul>
</li>
</ol>
<p>Now you should have a good looking check that should fit perfectly into your handsome double window self sealing envelope (which you probably purchased along with your checks).  Seal, mail and impress your vendors with your professional looking setup.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/how-to-print-an-85-x-35-check-in-quickbooks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to access the Internet through your phone (as a bluetooth modem)</title>
		<link>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem/</link>
		<comments>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 21:37:31 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Phones]]></category>
		<category><![CDATA[Wireless]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem/</guid>
		<description><![CDATA[Laptops are a great productivity tool, but without an Internet connection, they're a great deal less useful. This little article is about accessing the Internet from practically anywhere (well, anywhere you get a cellular signal, which is practically anywhere these days) through your cell phone.]]></description>
			<content:encoded><![CDATA[<p>Laptops are a great productivity tool, but without an Internet connection, they&#8217;re a great deal less useful. This little article is about accessing the Internet from practically anywhere (well, anywhere you get a cellular signal, which is practically anywhere these days) through your cell phone on your Windows laptop (Linux how-to coming soon)&#8230;</p>
<p><span id="more-6"></span></p>
<p>Please note that you must have a data plan and an unlimited data plan is highly recommended to keep you from incurring additional connection charges.</p>
<p><strong>Requirements</strong>: Any bluetooth enabled laptop and cellular phone should do, however, the steps below have been verified to work with Windows XP (Professional with SP2) running on the Dell Latitude D620 and Inspiron 1501  (Bluetooth Stack for Windows by Toshiba v.4.00.22(D)SP2) and the Nokia E62.</p>
<p>First thing is turn on (enable) Bluetooth on your laptop:</p>
<ol>
<li>If not already enabled, turn on Bluetooth (in the BIOS, for Dell, hit F2 when you first switch on the computer)</li>
<li>Right click the Bluetooth icon in the system tray and choose &#8220;Enable&#8221; or &#8220;Install&#8221;. The Blutooth icon is red when Bluetooth is disabled: <img src="http://giantdorks.org/alain/files/2007/11/bluetooth11.jpg" alt="bluetooth11.jpg" /> and white when enabled: <img src="http://giantdorks.org/alain/files/2007/11/bluetooth21.jpg" alt="bluetooth21.jpg" /></li>
</ol>
<p>Next, enable Bluetooth visibility on your phone:</p>
<ol>
<li> On the E62, go to Settings &#8211;&gt; Bluetooth and change &#8220;My phone&#8217;s visibility&#8221; to &#8220;Shown to All</li>
</ol>
<p>Now, we need to establish a Bluetooth connection between the laptop and the phone and create a new Dial Up Networking connection on the laptop utilizing the phone as the modem:</p>
<ol>
<li>Right click the Bluetooth icon in the system tray and choose &#8220;Add New Connection&#8221;</li>
<li>Choose &#8220;Custom Mode&#8221;</li>
<li>Your laptop will scan for nearby Bluetooth devices and display a list.  Choose your device (E62, in our case) and click &#8220;Next&#8221;</li>
</ol>
<p><img src="http://giantdorks.org/alain/files/2007/11/bluetooth3.jpg" alt="bluetooth3.jpg" /></p>
<ol>
<li>Laptop will ask for an authentication pin, make up a number and provide it (e.g. 1234) and click next, your phone should pop up an authentication box, provide the same code and choose to accept the connection.</li>
<li>In the box that follows you should have your phone as the connection name and *99# as the phone number.  I turned off the &#8220;Set as Default Dial-up&#8221; option because I want to control when to establish this connection rather than let Windows control that.</li>
<li>Click &#8220;Dial&#8221; and you should get connected</li>
</ol>
<p><img src="http://giantdorks.org/alain/files/2007/11/bluetooth6.jpg" alt="bluetooth6.jpg" /><br />
To get the status of your connection (such as bandwidth used), place your mouse cursor over the network icon.  To disconnect, right click and choose &#8220;Disconnect&#8221;.</p>
<p>That&#8217;s it, you&#8217;re all done!  Now you can get an Internet connection wherever you have a cellular singal.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/how-to-access-the-internet-through-your-phone-as-a-bluetooth-modem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to enable Searching for Recipient in RoundCube Webmail client</title>
		<link>http://giantdorks.org/alain/searching-for-recepient-in-roundcube-webmail-client/</link>
		<comments>http://giantdorks.org/alain/searching-for-recepient-in-roundcube-webmail-client/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 18:07:07 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[webmail]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/searching-for-recepient-in-roundcube-webmail-client/</guid>
		<description><![CDATA[In case you haven't heard, RoundCube is an awesome open source imap webmail client.  While still in beta, it works well for basic email use and it looks hot while doing it.  This post is about a simple edit to add recipient search to RoundCube's search function.]]></description>
			<content:encoded><![CDATA[<p><img src="http://giantdorks.org/alain/files/2007/12/r0undcube.jpg" alt="r0undcube.jpg" align="left" />I&#8217;m a big fan of <a href="http://roundcube.net/">RoundCube, the open source imap webmail client</a>. While still in beta and lacking some features, it&#8217;s free, licensed under the GPL, easily customized look due to reliance on CSS for styling, works great for basic email and is definitely one of the sexiest webmail clients out there.</p>
<p>One issue that had been bugging me is that it wouldn&#8217;t search for Recipient (&#8220;To&#8221;) by default. Only for Sender (&#8220;From&#8221;) or Subject.</p>
<p><span id="more-4"></span>The fix is actually very easy (thanks to the well organized and thoroughly commented php files that make up the application).  Just add the following highlighted items to <strong><em>/path/to/roundcube/</em>program/steps/mail/search.inc</strong></p>
<p><code><br />
// search in subject and sender by default<br />
else {<br />
$search = $IMAP-&gt;search($mbox, "HEADER SUBJECT", trim($str), $imap_charset);<br />
$search2 = $IMAP-&gt;search($mbox, "HEADER FROM", trim($str), $imap_charset);<br />
<font color="#ffcc00">$search3 = $IMAP-&gt;search($mbox, "HEADER TO", trim($str), $imap_charset);</font><br />
finish_search($mbox, array_unique(array_merge($search, $search2<strong>, </strong><font color="#ffcc00">$search3</font>)));<br />
}<br />
</code></p>
<p>That&#8217;s it! Gotta love open source.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/searching-for-recepient-in-roundcube-webmail-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trackback test</title>
		<link>http://giantdorks.org/alain/trackback-test/</link>
		<comments>http://giantdorks.org/alain/trackback-test/#comments</comments>
		<pubDate>Mon, 08 Jan 2007 08:45:28 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=442</guid>
		<description><![CDATA[Linking to a webteam blog post to see if a trackback gets automatically created.
]]></description>
			<content:encoded><![CDATA[<p>Linking to a <a href="http://blogs.law.stanford.edu/webteam/2009/10/02/we-got-first-request-for-a-blog/">webteam blog post</a> to see if a trackback gets automatically created.</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/trackback-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>test</title>
		<link>http://giantdorks.org/alain/test-2/</link>
		<comments>http://giantdorks.org/alain/test-2/#comments</comments>
		<pubDate>Sat, 01 Jan 2005 20:50:21 +0000</pubDate>
		<dc:creator>Alain Kelder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://giantdorks.org/alain/?p=571</guid>
		<description><![CDATA[testing
Mon May 10 13:56:47 PDT 2010
Mon May 10 13:57:33 PDT 2010
Mon May 10 13:58:15 PDT 2010
Mon May 10 14:15:46 PDT 2010
Mon May 10 14:49:55 PDT 2010
Mon May 10 15:16:08 PDT 2010
]]></description>
			<content:encoded><![CDATA[<p>testing</p>
<p>Mon May 10 13:56:47 PDT 2010<br />
Mon May 10 13:57:33 PDT 2010<br />
Mon May 10 13:58:15 PDT 2010<br />
Mon May 10 14:15:46 PDT 2010<br />
Mon May 10 14:49:55 PDT 2010<br />
Mon May 10 15:16:08 PDT 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://giantdorks.org/alain/test-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
