<?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>The eflow blog &#187; scripting</title>
	<atom:link href="http://blog.eflow.org/archives/tag/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.eflow.org</link>
	<description>Insert some amazingly witty tagline here</description>
	<lastBuildDate>Fri, 23 Apr 2010 03:19:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript Night Clock</title>
		<link>http://blog.eflow.org/archives/274</link>
		<comments>http://blog.eflow.org/archives/274#comments</comments>
		<pubDate>Sun, 24 Jan 2010 01:15:44 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[babble]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[kenya]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=274</guid>
		<description><![CDATA[Kenya seems to loathe alarm clocks.  Ubuntu&#8217;s clock screen saver is sub-par, so I wrote a quick javascript clock to open in my browser and display all night long.
nightclock.html
After opening the file in your favorite browser you can press F11 to hide all the toolbars.
 ]]></description>
			<content:encoded><![CDATA[<p>Kenya seems to loathe alarm clocks.  Ubuntu&#8217;s clock screen saver is sub-par, so I wrote a quick javascript clock to open in my browser and display all night long.</p>
<p><a href='http://blog.eflow.org/wp-content/uploads/2010/01/nightclock.html'>nightclock.html</a></p>
<p>After opening the file in your favorite browser you can press F11 to hide all the toolbars.</p>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=274" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/274/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Uuids XML Attribute &#8211; Sed Script</title>
		<link>http://blog.eflow.org/archives/238</link>
		<comments>http://blog.eflow.org/archives/238#comments</comments>
		<pubDate>Wed, 20 May 2009 16:50:41 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[openmrs]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sh]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=238</guid>
		<description><![CDATA[OpenMRS recently added a non-null uuid column to every table.  All of our dbunit xml files needed to be updated to insert values for this attribute.  I wrote the following shell script to loop over all xml files under the current folder and add a uuid attribute to all rows that didn&#8217;t have an attribute [...]]]></description>
			<content:encoded><![CDATA[<p>OpenMRS recently added a non-null uuid column to every table.  All of our dbunit xml files needed to be updated to insert values for this attribute.  I wrote the following shell script to loop over all xml files under the current folder and add a uuid attribute to all rows that didn&#8217;t have an attribute already.  There is a bit of logic in there to ignore certain tables because those tables didn&#8217;t actually get any uuids.</p>
<p><span id="more-238"></span></p>
<p>You also can download the <a href="http://blog.eflow.org/wp-content/uploads/2009/05/add_uuids.sh">add_uuids</a> script.</p>
<blockquote>
<pre>
#!/bin/sh

# This script adds a uuid entry to each element in an xml file
# Author: Ben Wolfe - Apr 2009
# http://blog.eflow.org

date
path=`pwd`

# get a flat list of all files under the current directory
f=`ls -RlQ | awk -v PATH=$path '{ \
if ($1 ~ /.*:$/) \
path = substr($1,3,length($1)-4); \
else \
if ($0 ~ /^-/) \
printf("%s%s/%s\n", PATH, path, \
substr($0, match($0,"\".*\"")+1, RLENGTH-2) \
) \
}'`

# create a sed command that adds a generated uuid attribute to all elements that don't contain uuid:
# @UUIDGEN@ needs to get replaced later with the generated uuid
command="/uuid/!{s/\/>/ uuid=\"@UUIDGEN@\"\/>/}"
# ignore rows with &lt;users, &lt;patient, &lt;user_role, &lt;location_tag, &lt;concept_word, &lt;user_privilege, etc because they don't have a uuid column
for word in "&lt;patient " "&lt;user_role " "&lt;location_tag " "&lt;concept_word " "&lt;concept_numeric " "&lt;concept_derived " "&lt;complex_obs " "&lt;role_role " "&lt;role_privilege " "&lt;scheduled_task_config " "&lt;scheduler_task_config_property " "&lt;drug_order " "&lt;concept_complex " "&lt;concept_name_tag_map " "&lt;cohort " "&lt;cohort_member " "&lt;location_tag_map " "&lt;users "
do
   command="/$word/!{$command}"
done

for i in $f
do
#ignore the .svn folder contents
if ! echo $i | grep .svn > /dev/null;
then
    # get the file's extension
    ext=`echo "$i" | awk -F . '{print $NF}'`

    # only execute on xml files
    case $ext in
         xml)
            echo acting on $i

            # blank out the IFS variable so that the "while read line" doesn't delete leading whitespace
            OIFS=$IFS
            IFS=

            while read line
            do
                uuid=`uuidgen`
                newcommand=`echo $command | sed -e "s/@UUIDGEN@/$uuid/"`
                # run the command on the current line
                echo "$line" | sed -e "$newcommand" >> $i.new
            done < $i

            # reset the IFS variable to what it was before
            IFS=$OIFS

            mv -f "$i.new" "$i"

            ;;
        *)
            echo invalid extension: $ext
            ;;
        esac
fi
done

echo "done"
date
</pre>
</blockquote>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=238" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Multiple Monitors in Intrepid Ibex</title>
		<link>http://blog.eflow.org/archives/175</link>
		<comments>http://blog.eflow.org/archives/175#comments</comments>
		<pubDate>Tue, 24 Mar 2009 01:47:09 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[babble]]></category>
		<category><![CDATA[Intrepid Ibex]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=175</guid>
		<description><![CDATA[For some reason Ubuntu regressed a bit in the multiple monitor department between Hardy and Intrepid.  Before upgrading I was able to dock my Thinkpad and easily switch screens using fn-f7 to switch resolutions just like in the Windows World.  After upgrading function f7 usually didn&#8217;t work so I had to start just shutting down [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason Ubuntu regressed a bit in the multiple monitor department between Hardy and Intrepid.  Before upgrading I was able to dock my Thinkpad and easily switch screens using fn-f7 to switch resolutions just like in the Windows World.  After upgrading function f7 usually didn&#8217;t work so I had to start just shutting down the computer (or at least control-alt-backspacing to restart x) if I switched between external monitor and the laptop monitor.</p>
<p>I recently discovered &#8220;grandr&#8221; and its capabilities.  It worked more often than Ubuntu&#8217;s Screen Resolution program&#8230;but I had to use my mouse and see the screen to do so.  This meant that I had to the lcd before I did a stand by or took the laptop off the dock.</p>
<p>I then discovered the command line &#8220;xrandr&#8221; program.  It let me set up some scripts to switch the screen resolution.</p>
<ul>
<li>Use open source ATI driver (not fglrx)</li>
<li>Set up your terminal to launch with a keyboard shortcut (System&#8211;&gt;Preferences&#8211;&gt;Keyboard Shortcuts)</li>
<li> Figure out what randr calls the lcd and vga video card outputs with just xrandr</li>
<li>Create ./lcd.sh and ./vga.sh and set them to be executable with chmod +x</li>
</ul>
<p>lcd.sh:</p>
<blockquote><p>/usr/bin/xrandr &#8211;screen LVDS &#8211;auto</p></blockquote>
<p>vga.sh:</p>
<blockquote><p>/usr/bin/xrandr &#8211;screen &#8220;VGA-0&#8243; &#8211;auto<br />
/bin/sleep 4<br />
/usr/bin/xrandr &#8211;screen LVDS &#8211;output LVDS &#8211;off</p></blockquote>
<p><br/></p>
<div>
Now after undocking I don&#8217;t need to be able to see the screen to turn on the lcd.  I just type Alt-t to bring up the terminal, then ./lcd.sh and the lcd turns on. <img src='http://blog.eflow.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Jaunty is supposed to have improved monitor support, so I&#8217;m looking forward to its release.
</div>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=175" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/175/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing SVN Inconsistent Newlines</title>
		<link>http://blog.eflow.org/archives/130</link>
		<comments>http://blog.eflow.org/archives/130#comments</comments>
		<pubDate>Mon, 03 Nov 2008 15:21:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[openmrs]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=130</guid>
		<description><![CDATA[I&#8217;ve spoken previously about the travails of having a developer community that uses both Windows and Unix-based machines: merging files edited in both environments. Hopefully those days are over. (At least for the OpenMRS community)

Chase Yarbrough attempted to fix this by adding the svn:eol-style to all of the files in the OpenMRS repository recursively.  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve <a href="http://blog.eflow.org/archives/45">spoken previously</a> about the travails of having a developer community that uses both Windows and Unix-based machines: merging files edited in both environments. Hopefully those days are over. (At least for the OpenMRS community)<br />
<span id="more-130"></span></p>
<p>Chase Yarbrough <a href="http://dev.openmrs.org/changeset/4095">attempted to fix</a> this by adding the svn:eol-style to all of the files in the OpenMRS repository recursively.  The problem is that all files that were already committed from both operating systems failed with:</p>
<blockquote><p>
svn: File &#8217;somefilename.ext&#8217; has inconsistent newlines<br />
svn: Inconsistent line ending style
</p></blockquote>
<p>However, merging continued to be a pain with those files that were skipped over.  </p>
<p><br/></p>
<h3>Solution</h3>
<p>I created a short script to recursively loop over all files in the root directory, run dos2unix, and then set the svn:eol-style to CRLF:</p>
<p><a href='http://blog.eflow.org/wp-content/uploads/2008/12/fix_newlines.sh'>Download this script</a></p>
<blockquote>
<pre>
#!/bin/sh

# This script normalizes the newlines in all files in
# a directory and adds the svn:eol-style property
# Author: Ben Wolfe - 10/2008
# http://blog.eflow.org

path=`pwd`

# get a flat list of all files under the current directory
f=`ls -RlQ | awk -v PATH=$path '{ \
if ($1 ~ /.*:$/) \
path = substr($1,3,length($1)-4); \
else \
if ($0 ~ /^-/) \
printf("%s%s/%s\n", PATH, path, \
substr($0, match($0,"\".*\"")+1, RLENGTH-2) \
) \
}'`

for i in $f
do
#ignore the build folder contents
if ! echo $i | grep build > /dev/null;
then
        #check subversion for this property
        x=`svn propget svn:eol-style $i`
        if [ ! -n "$x" ]
        then
                # get the file's extension
                ext=`echo "$i" | awk -F . '{print $NF}'`

                # This is an "if list contains" method for shell scripts
                # check if ext is one of the text based extensions
                case $ext in
                        java|jsp|css|js|xml|sql|txt|properties|tld|tag|html|htm|sh)
                                #echo No svn:eol-style prop: $i . Adding now.
                                dos2unix -a $i
                                svn propset svn:eol-style "CRLF" $i
                                ;;
                        *)
                                echo invalid extension: $ext
                                ;;
                esac
        fi
fi
done

echo "done"
</pre>
</blockquote>
<p>I committed all changes from running this script in <a href="http://dev.openmrs.org/changeset/5893">changeset 5893</a>.</p>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=130" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/130/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Cron Script for Checking Server Status</title>
		<link>http://blog.eflow.org/archives/27</link>
		<comments>http://blog.eflow.org/archives/27#comments</comments>
		<pubDate>Wed, 27 Feb 2008 16:02:52 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[babble]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://eflow.org/blog/archives/27</guid>
		<description><![CDATA[I wrote this little cron script (with help from Adam Aisen) so that I could keep track of our tomcat server.  I wanted to be notified by email whenever our site was down (which is does occasionally due to out of memory errors).  The shell script simply looks at the http status code [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this little cron script (with help from Adam Aisen) so that I could keep track of our tomcat server.  I wanted to be notified by email whenever our site was down (which is does occasionally due to out of memory errors).  The shell script simply looks at the http status code and sends an email to the given email address if the site has anything but a &#8220;200 OK&#8221; code.</p>
<blockquote><p>#!/bin/sh</p>
<p># input validation<br />
if [ ! -n "$1" ]<br />
then<br />
echo &#8220;You must enter a url as the first parameter&#8221;<br />
echo &#8220;Usage: $0 &lt;url&gt; &lt;emailaddress&gt;[,&lt;emailaddress&gt;]&#8221;<br />
exit<br />
fi</p>
<p># input validation<br />
if [ ! -n "$2" ]<br />
then<br />
echo &#8220;You must enter an email address to notify as the second parameter&#8221;<br />
echo &#8220;Usage: $0 &lt;url&gt; &lt;emailaddress&gt;[,&lt;emailaddress&gt;]&#8221;<br />
exit<br />
fi</p>
<p># the default mail message<br />
y=&#8221;The following services are broken!  Oh noes!  &#8221;<br />
z=0</p>
<p># fetch the page and look for the &#8220;200&#8243; header<br />
x=`wget -O &#8211; -q &#8211;save-headers $1 | grep &#8220;HTTP/1.1 200 OK&#8221;`<br />
if [ ! -n "$x" ]<br />
then<br />
y=$y&#8221;\n\n$1 &#8221;<br />
z=1<br />
fi</p>
<p># if one or more site above triggered an error, send the email<br />
if test $z -eq 1<br />
then<br />
echo -e $y | mail $2 -s&#8221;Server status&#8221;</p></blockquote>
<p>You call this script like so:</p>
<blockquote><p>./serverstatus demo.openmrs.org/openmrs someuser@eflow.org</p></blockquote>
<p>Now call this command as a cron job hourly/daily/minutely and you&#8217;re all set!</p>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=27" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/27/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
