<?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>NeapTide</title>
	<atom:link href="http://neaptide.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://neaptide.org</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 17 May 2013 14:04:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.3</generator>
		<item>
		<title>Holidays and Office Hours for Asterisk</title>
		<link>http://neaptide.org/2012/12/asterisk-office-hours/</link>
		<comments>http://neaptide.org/2012/12/asterisk-office-hours/#comments</comments>
		<pubDate>Sat, 15 Dec 2012 22:50:38 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[agi]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[Date::Holidays]]></category>
		<category><![CDATA[dialplan]]></category>
		<category><![CDATA[exten]]></category>
		<category><![CDATA[extensions.conf]]></category>
		<category><![CDATA[german]]></category>
		<category><![CDATA[GotoIfTime]]></category>
		<category><![CDATA[holiday]]></category>
		<category><![CDATA[holiday check]]></category>
		<category><![CDATA[holidays]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[voip]]></category>

		<guid isPermaLink="false">http://neaptide.org/?p=9123</guid>
		<description><![CDATA[Office phones have to be online at office hours, otherwise a voicemail should be enabled. They should also be aware of holidays. A little perl-script checks for german holidays: The dialplan ; extensions.conf exten =&#62; 1234567,n,GotoIfTime(09:00-18:00,mon-fri,*,*?hcheck:vm) exten =&#62; 1234567,n,GotoIfTime(09:00-14:00,sat,*,*?hcheck:vm) exten =&#62; 1234567,n(hcheck),AGI(isholiday.pl) exten =&#62; 1234567,n,GotoIf($[${ISHOLIDAY} = &#34;YES&#34;]?vm) exten =&#62; 1234567,n(open),NoOp ... exten =&#62; 1234567,n(vm),VoiceMail(1234567,sub) ... [...]]]></description>
			<content:encoded><![CDATA[<p>Office phones have to be online at office hours, otherwise a voicemail should be enabled. They should also be aware of holidays. A little perl-script checks for german holidays:</p>
<p>The dialplan</p>
<pre class="prettyprint ">
; extensions.conf
exten =&gt; 1234567,n,GotoIfTime(09:00-18:00,mon-fri,*,*?hcheck:vm)
exten =&gt; 1234567,n,GotoIfTime(09:00-14:00,sat,*,*?hcheck:vm)
exten =&gt; 1234567,n(hcheck),AGI(isholiday.pl)
exten =&gt; 1234567,n,GotoIf($[${ISHOLIDAY} = &quot;YES&quot;]?vm)
exten =&gt; 1234567,n(open),NoOp
...
exten =&gt; 1234567,n(vm),VoiceMail(1234567,sub)
...
</pre>
<p>The AGI:</p>
<pre class="prettyprint ">
#!/usr/bin/perl
# holiday check for asterisk
# /var/lib/asterisk/agi-bin/isholiday.pl

use strict;
my ($isholiday, $today,$ymd);

END { printf &quot;SET VARIABLE ISHOLIDAY %s\n\n&quot;, ($isholiday)?&quot;YES&quot;:&quot;NO&quot;; }

while(&lt;STDIN&gt;) {
     chomp;
     last unless length($_);
}

use Date::Holidays::DE qw(holidays);

my $feiertage_ref = holidays(
    WHERE    =&gt; [ 'common', 'ni'], # ni = Niedersachsen
    FORMAT   =&gt; &quot;%F&quot;,
    YEAR     =&gt; 1900 + (localtime())[5],
    ADD      =&gt; [ 'heil', 'wei1', 'wei2',
                  'osts', 'ostm', 'pfis',
                  'pfim', '3okt', 'silv',
                  'mari' ]);

my (@ymd) = (localtime)[5,4,3];
$today = sprintf &quot;%s-%s-%s&quot;, 1900+$ymd[0], 1+$ymd[1], $ymd[2];

for my $d (@$feiertage_ref) {
    if ($d eq $today) {
        $isholiday = 1;
        last;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://neaptide.org/2012/12/asterisk-office-hours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Little Helpers</title>
		<link>http://neaptide.org/2012/12/script-debugging/</link>
		<comments>http://neaptide.org/2012/12/script-debugging/#comments</comments>
		<pubDate>Sat, 15 Dec 2012 07:32:45 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://neaptide.org/?p=9108</guid>
		<description><![CDATA[There is often a need to debug scripts which are started by daemons, so you have no input/output available. The following snippet easily redirects stdout and stderr to a file: #!/bin/bash exec &#62;&#62; /tmp/script_debug.log 2&#62;&#38;1 set -x echo Start: $(date) : buggy code echo Stop: $(date) and here the output: $ cat /tmp/script_debug.log ++ date [...]]]></description>
			<content:encoded><![CDATA[<p>There is often a need to debug scripts which are started by daemons, so you have no input/output available. The following snippet easily redirects stdout and stderr to a file:</p>
<pre class="prettyprint ">
#!/bin/bash

exec &gt;&gt; /tmp/script_debug.log 2&gt;&amp;1
set -x 

echo Start: $(date)

: buggy code

echo Stop: $(date)
</pre>
<p>and here the output:</p>
<pre>
$ cat /tmp/script_debug.log
++ date
+ echo Start: Sat Dec 15 08:37:45 CET 2012
Start: Sat Dec 15 08:37:45 CET 2012
+ your-buggy-cmd
foo: line 8: your-buggy-cmd: command not found
++ date
+ echo Stop: Sat Dec 15 08:37:45 CET 2012
Stop: Sat Dec 15 08:37:45 CET 2012
</pre>
]]></content:encoded>
			<wfw:commentRss>http://neaptide.org/2012/12/script-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parallel Bash #2</title>
		<link>http://neaptide.org/2011/11/parallel-bash-2/</link>
		<comments>http://neaptide.org/2011/11/parallel-bash-2/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 18:08:54 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[benchmark bench shell]]></category>
		<category><![CDATA[parallel]]></category>

		<guid isPermaLink="false">http://neaptide.org/?p=203</guid>
		<description><![CDATA[The first part of Parallel Bash dealt with creation of parallel processes, so now it&#8217;s time for a real parallel tool. The Apache benchmark tool ab has the disadvantage of sending only one URL for requests. To emulate a real server load we need some tools which can download several different files (.jpg, .js, .php, [...]]]></description>
			<content:encoded><![CDATA[<p>The first part of <a href="http://neaptide.org/?p=49">Parallel Bash</a> dealt with creation of parallel processes, so now it&#8217;s time for a real parallel tool.</p>
<p>The Apache benchmark tool <em><strong>ab</strong></em> has the disadvantage of sending only one URL for requests. To emulate a real server load we need some tools which can download several different files (.jpg, .js, .php, .css, ..) where each of them causes different CPU loads and network througphut, as well as different sizes of tranfered data. This can easily be done with <a title="HTTrack" href="http://www.httrack.com/" target="_blank"><strong>httrack</strong></a> or <a title="GNU Wget" href="http://www.gnu.org/s/wget/" target="_blank"><strong>wget</strong></a>.</p>
<p>And here is how:</p>
<p>The parallel routine <em><strong>pwork</strong></em> runs a site-mirror and collects the elapsed time in a log file</p>
<pre class="prettyprint ">
...
HTLOG=/tmp/httime.$$.log

pwork () {
    TMPDIR=$(mktemp -d /tmp/htbench_instance_XXXXX)
    TMPFILE=$(mktemp /tmp/htbench_log_XXXX)
    ( cd $TMPDIR
      #  append elapsed time to HTLOG
      /usr/bin/time -f &quot;%e&quot; -o $TMPFILE
      httrack -c8 --mirror --depth=2 -Q -q $1
      if lockfile -1 -r12 $HTLOCK; then
          cat $TMPFILE &gt;&gt; $HTLOG
      fi
      rm -f $HTLOCK $TMPFILE
    )
    rm -rf &quot;$TMPDIR&quot;
}
...
</pre>
<p>Limit the benchmark to n loops:</p>
<pre class="prettyprint ">
...
while [ $COUNT != 0 ]
do      J=$(jobs -p)
        echo &quot;jobs left: &quot;$COUNT
        N=$(echo $J|wc -w)
        if [ -z &quot;$N&quot; -o &quot;$N&quot; -lt $PARALLEL ]; then
            pwork &quot;$URI&quot; &amp;
            (( COUNT-- ))
        fi
        sleep .2
done
</pre>
<p>Show final results:</p>
<pre class="prettyprint ">
...
show_results () {

    MINRUN=$(sort -n $HTLOG|head -1|cut -d' ' -f1)
    MAXRUN=$(sort -n $HTLOG|tail -1|cut -d' ' -f1)
    AVGRUN=$(perl -e '$sum=$count=0;
                         while (&lt;&gt;) {
                             chomp;$sum+=$_;$count++; }
                          printf &quot;%.2fn&quot;, $sum/$count;' $HTLOG)
    rm $HTLOG

    echo &quot;Benchmark Results&quot;
    echo &quot;=================&quot;
    echo
    echo &quot;longest runtime:  &quot;$MAXRUN
    echo &quot;shortest runtime: &quot;$MINRUN
    echo &quot;average runtime:  &quot;$AVGRUN
    echo
}

reaper () {
        echo &quot;waiting to finish $RUNNING&quot; &gt;&amp;2
        wait
        show_results
        exit 0
}

trap reaper 0 1 2 3 11 15
...
</pre>
<p><br/></p>
<div class="su-note" style="background-color:#e09393;border:1px solid #c26c6c">
<div class="su-note-shell" style="border:1px solid #f7e4e4;color:#412424"> Use with care! </div>
</div>
<p>Download latest version:<br />
<a href="http://neaptide.org/files/htbench.sh" class="piwik_download su-button su-button-style-4 su-button-class" style="background-color:#ccc;border:1px solid #a3a3a3;border-radius:0px;-moz-border-radius:0px;-webkit-border-radius:0px;"><span style="color:#3d3d3d;padding:4px 13px;font-size:13px;height:13px;line-height:13px;border-top:1px solid #f0f0f0;border-radius:0px;text-shadow:1px 1px 0 #e6e6e6;-moz-border-radius:0px;-moz-text-shadow:1px 1px 0 #e6e6e6;-webkit-border-radius:0px;-webkit-text-shadow:1px 1px 0 #e6e6e6;"> htbench.sh </span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://neaptide.org/2011/11/parallel-bash-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parallel Processing with Bash</title>
		<link>http://neaptide.org/2011/08/bash-parallel-processing/</link>
		<comments>http://neaptide.org/2011/08/bash-parallel-processing/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 14:20:02 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://neaptide.org/?p=49</guid>
		<description><![CDATA[There is often the need to run several bash scripts in parallel. To achieve this, one need to keep track of the running processes. Here&#8217;s my solution: #!/bin/bash # parallel child processes PP=5 if [ -n &#34;$1&#34; ]; then sleep $1 exit fi reaper () { echo &#34;waiting to finish&#34; &#62;&#38;2 wait exit 0 } [...]]]></description>
			<content:encoded><![CDATA[<p>There is often the need to run several bash scripts in parallel. To achieve this, one need to keep track of the running processes. Here&#8217;s my solution:</p>
<pre class="prettyprint ">
#!/bin/bash

# parallel child processes
PP=5

if [ -n &quot;$1&quot; ]; then
        sleep $1
        exit
fi

reaper () {
        echo &quot;waiting to finish&quot; &gt;&amp;2
        wait
        exit 0
}
trap reaper 0 1 2 3 11 15

while :;
do      J=$(jobs -p)
        echo &quot;running: &quot;$J
        N=$(echo $J|wc -w)
        if [ -z &quot;$N&quot; -o &quot;$N&quot; -lt $PP ]; then
            $0 $[ $RANDOM % 8 ] &amp;
        fi

        sleep .2
done</pre>
<p>Paste this snippet to a file, and set the executable flag.</p>
<pre>
$ cat > parallel.sh
$ chmod +x parallel.sh
</pre>
<p>The output will look like this:</p>
<pre>$ ./parallel.sh
running:
running: 25431
running: 25431 25438
running: 25431 25438 25445
running: 25431 25438 25445 25452
running: 25438 25445 25452 25459
running: 25445 25459 25466
running: 25445 25459 25466 25473
running: 25445 25459 25466 25480
running: 25445 25459 25466 25480 25487
running: 25459 25466 25480 25487
running: 25459 25466 25480 25487 25499
running: 25459 25466 25487 25499
running: 25459 25466 25487 25499 25511
running: 25466 25487 25499 25511
running: 25466 25487 25499 25511 25524
running: 25466 25487 25499 25511 25524
running: 25466 25487 25499 25524
running: 25487 25499 25524 25541
running: 25487 25499 25524 25541 25548
running: 25487 25524 25541 25548
running: 25524 25541 25560
running: 25524 25560 25567
running: 25524 25560 25567 25574
running: 25560 25567 25581
running: 25560 25567 25581 25588
running: 25560 25567 25581 25588 25595
^Cwaiting to finish
waiting to finish
$</pre>
<p>Comments are welcome.</p>
<p>See also a similar solution of Grumbel: <a title="Parallel Bash" href="http://grumbel.blogspot.com/2009/05/parallel-bash.html" target="_blank">Parallel Bash</a></p>
]]></content:encoded>
			<wfw:commentRss>http://neaptide.org/2011/08/bash-parallel-processing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: neaptide.org @ 2013-05-22 20:44:08 -->