<?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>Subjectively &#187; OS X</title>
	<atom:link href="http://kirk.webfinish.com/category/os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://kirk.webfinish.com</link>
	<description>dd if=/dev/random &#124; kirk &#62; blog</description>
	<lastBuildDate>Wed, 04 Jan 2012 15:48:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://kirk.webfinish.com/?pushpress=hub'/>
		<item>
		<title>csv2pg &#8212; Load a comma separated values file into postgresql</title>
		<link>http://kirk.webfinish.com/2010/01/csv2pg-load-a-comma-separated-values-file-into-postgresql/</link>
		<comments>http://kirk.webfinish.com/2010/01/csv2pg-load-a-comma-separated-values-file-into-postgresql/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 21:54:48 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=102</guid>
		<description><![CDATA[Here&#8217;s a simple wrapper script that I wrote in bash for bulk loading data into PostgreSQL from csv files. Beware, it also does a code page conversion at the end that you may not want. That part should be parameterized, I just haven&#8217;t gotten around to it yet. Link to the download is here 1 [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple wrapper script that I wrote in bash for bulk loading data into PostgreSQL from csv files.  Beware, it also does a code page conversion at the end that you may not want.  That part should be parameterized, I just haven&#8217;t gotten around to it yet.</p>
<p>Link to the download is <a href="http://kirk.webfinish.com/csv2pg/csv2pg-0.1.tar.gz">here</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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
</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;">#</span>
<span style="color: #666666; font-style: italic;">#          FILE:  csv2pg</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./csv2pg [-d|--debug] [-v|--version] -c[|--csv] filename [-s|--schema schemaname]</span>
<span style="color: #666666; font-style: italic;">#                 [-b|--database database] [-u|--user username] -t[|--table] tablename [-o|--ouput]</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  load a csv file into a prepared table</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#       OPTIONS:  ---</span>
<span style="color: #666666; font-style: italic;">#  REQUIREMENTS:  ---</span>
<span style="color: #666666; font-style: italic;">#          BUGS:  ---</span>
<span style="color: #666666; font-style: italic;">#         NOTES:  This script can be used in conjunction with csvheader2createtable</span>
<span style="color: #666666; font-style: italic;">#                 to create a table with ETL tracking fields and load the data.</span>
<span style="color: #666666; font-style: italic;">#                 (e.g.</span>
<span style="color: #666666; font-style: italic;">#                   for file in *.csv</span>
<span style="color: #666666; font-style: italic;">#                   do</span>
<span style="color: #666666; font-style: italic;">#                     csvheader2createtable -s myschema $file | psql</span>
<span style="color: #666666; font-style: italic;">#                     csv2pg -s myschema -t ${file//.csv} $file</span>
<span style="color: #666666; font-style: italic;">#                   done</span>
<span style="color: #666666; font-style: italic;">#                 )</span>
<span style="color: #666666; font-style: italic;">#                 Assuming the naming convention for the files was sane...</span>
<span style="color: #666666; font-style: italic;">#        AUTHOR:  Kirk Roybal (DBA), kirk.roybal@javelindirect.com</span>
<span style="color: #666666; font-style: italic;">#       COMPANY:  Javelin</span>
<span style="color: #666666; font-style: italic;">#       VERSION:  1.0</span>
<span style="color: #666666; font-style: italic;">#       CREATED:  12/21/2009 14:32:37 CST</span>
<span style="color: #666666; font-style: italic;">#      REVISION:  ---</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> usage <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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
  $0 [--help] [-d|--debug] [-v|--version] -c[|--csv] filename [-s|--schema schemaname]
     [-b|--database database] [-u|--user username] -t[|--table] tablename [-o|--ouput]
EOS</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${#*}</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  usage
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;0.1&quot;</span>
<span style="color: #000000; font-weight: bold;">for</span> arg 
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$arg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #666666; font-style: italic;">#translate --gnu-long-options to -g (short options) </span>
    --help<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-z &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --csv<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-c &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --host<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-h &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --database<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-b &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --user<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-u &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --schema<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-s &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --output<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-o &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --table<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-t &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --debug<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-d &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --version<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-v &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #666666; font-style: italic;">#pass through anything else</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">leftchar</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #000000; font-weight: bold;">%</span>1.1s <span style="color: #ff0000;">&quot;<span style="color: #007800;">$arg</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <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: #000000; font-weight: bold;">!</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$leftchar</span>&quot;</span> == <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
      <span style="color: #000000; font-weight: bold;">fi</span>
      <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span><span style="color: #007800;">${delim}</span><span style="color: #007800;">${arg}</span><span style="color: #007800;">${delim}</span> &quot;</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Reset the positional parameters to the short options</span>
<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$args</span>
&nbsp;
<span style="color: #007800;">schema</span>=public
<span style="color: #007800;">host</span>=db1
<span style="color: #007800;">database</span>=warehouse
<span style="color: #007800;">user</span>=warehouse
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;:b:c:dh:os:t:u:vz&quot;</span> option <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$option</span> <span style="color: #000000; font-weight: bold;">in</span>
    o<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">output</span>=<span style="color: #c20cb9; font-weight: bold;">true</span><span style="color: #000000; font-weight: bold;">;;</span>
    h<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">host</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    b<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">database</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    u<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    d<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span> ; <span style="color: #007800;">debug</span>=<span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">;;</span>
    v<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;">$(basename $0)</span> <span style="color: #007800;">$version</span>&quot;</span>; <span style="color: #7a0874; font-weight: bold;">exit</span><span style="color: #000000; font-weight: bold;">;;</span>
    c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">csvfile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">schema</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    t<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">table</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    z<span style="color: #7a0874; font-weight: bold;">&#41;</span> usage; <span style="color: #7a0874; font-weight: bold;">exit</span><span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$OPTARG</span> is an unrecognized option; usage; <span style="color: #7a0874; font-weight: bold;">exit</span><span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csvfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;must have csv file&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>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csvfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;csv file not found&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;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$table</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;table name is required&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: #007800;">sql</span>=<span style="color: #ff0000;">&quot;SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS 
      WHERE table_name = '<span style="color: #007800;">$table</span>' and table_schema='<span style="color: #007800;">$schema</span>'
      AND column_name NOT IN ('id','date_stamp')
      ORDER BY ordinal_position;&quot;</span>
<span style="color: #007800;">fields</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>psql <span style="color: #660033;">-h</span> <span style="color: #007800;">$host</span> <span style="color: #660033;">-U</span> <span style="color: #007800;">$user</span> <span style="color: #007800;">$database</span> <span style="color: #660033;">-qtAc</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #ff0000;">', '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/, &quot;$//'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^/&quot;/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/,/&quot;, &quot;/g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/loaded_from.*/loaded_from&quot;/'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$fields</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;table <span style="color: #007800;">$table</span> does not exist&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: #007800;">trailing_comma</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csvfile</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/[[:space:]]*$//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">trailing_comma</span>=<span style="color: #800000;">${trailing_comma:${#trailing_comma}</span>-<span style="color: #000000;">1</span>:<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$trailing_comma</span>&quot;</span> == <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">''</span> <span style="color: #ff0000;">'s/,[[:space:]]*$//'</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csvfile</span>&quot;</span>
&nbsp;
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;COPY <span style="color: #007800;">$schema</span>.<span style="color: #007800;">$table</span>(<span style="color: #007800;">$fields</span>) FROM STDIN WITH CSV HEADER;&quot;</span>
<span style="color: #666666; font-style: italic;">#code page conversion, append control data, insert</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$output</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;iconv -f ibm850 -t utf8 <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$csvfile</span><span style="color: #000099; font-weight: bold;">\&quot;</span> | 
  tr -d '\\000' | tr '\<span style="color: #000099; font-weight: bold;">\r</span>' '\<span style="color: #000099; font-weight: bold;">\n</span>' | 
  sed -e '/^[[:space:]]*<span style="color: #000099; font-weight: bold;">\$</span>/d' -e '/^,*$/d' -e <span style="color: #000099; font-weight: bold;">\&quot;</span>s/\<span style="color: #000099; font-weight: bold;">\$</span>/,klr,<span style="color: #007800;">$csvfile</span>/<span style="color: #000099; font-weight: bold;">\&quot;</span> | 
  psql -h <span style="color: #007800;">$host</span> -U <span style="color: #007800;">$user</span> <span style="color: #007800;">$database</span> -c <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$sql</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
&nbsp;
iconv <span style="color: #660033;">-f</span> ibm850 <span style="color: #660033;">-t</span> utf8 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csvfile</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">'\000'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">'\r'</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #000000; font-weight: bold;">|</span> 
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^[[:space:]]*$/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^,*$/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/<span style="color: #000099; font-weight: bold;">\$</span>/,klr,<span style="color: #007800;">$csvfile</span>/&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
  psql <span style="color: #660033;">-h</span> <span style="color: #007800;">$host</span> <span style="color: #660033;">-U</span> <span style="color: #007800;">$user</span> <span style="color: #007800;">$database</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2010/01/csv2pg-load-a-comma-separated-values-file-into-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xlsx2csv &#8211; Excel xlsx (spreadsheetML) to CSV bash script</title>
		<link>http://kirk.webfinish.com/2009/12/xlsx2csv/</link>
		<comments>http://kirk.webfinish.com/2009/12/xlsx2csv/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 20:41:51 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=91</guid>
		<description><![CDATA[Read an MS excel SpreadsheetML document and extracts the data to csv]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a link to the <a href="http://kirk.webfinish.com/xlsx2csv/xlsx2csv-1.2.tar.gz">tar.gz</a>.</p>
<p>Here is the code to convert an xlsx document to csv.</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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
</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;">#</span>
<span style="color: #666666; font-style: italic;">#          FILE:  xlsx2csv.sh</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./xlsx2csv.sh [-c|--copyleft] [-d|--debug] [-v|--version] -x[|--xlsx] filename</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  Read an MS excel SpreadsheetML document </span>
<span style="color: #666666; font-style: italic;">#                   extract the data to csv</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#  REQUIREMENTS:  unzip | xsltproc | libxml | sqlite3 | gnu sed | mktemp</span>
<span style="color: #666666; font-style: italic;">#          BUGS:  doesn't read formatting, macros</span>
<span style="color: #666666; font-style: italic;">#         NOTES:  does translate dates correctly! also handles null data</span>
<span style="color: #666666; font-style: italic;">#                 quotes and commas delimited, embedded quotes are doubled</span>
<span style="color: #666666; font-style: italic;">#        AUTHOR:  Kirk Roybal (DBA)</span>
<span style="color: #666666; font-style: italic;">#                 http://kirk.webfinish.com</span>
<span style="color: #666666; font-style: italic;">#       CREATED:  12/02/2009 10:06:45 CST</span>
<span style="color: #666666; font-style: italic;">#      REVISION:  ---</span>
<span style="color: #666666; font-style: italic;">#       CREDITS:</span>
<span style="color: #666666; font-style: italic;">#     openxmldeveloper.org for describing the format of excel date serial</span>
<span style="color: #666666; font-style: italic;">#     http://openxmldeveloper.org/articles/using_Spreadsheet_ML_document__as_datasource_for_heterogenous_applicationss.aspx</span>
<span style="color: #666666; font-style: italic;">#     http://www.ccechile.org/eventos/2007/docs/document/Response-various_Dates.pdf</span>
<span style="color: #666666; font-style: italic;">#     http://www.codeproject.com/KB/XML/ooxml_is_defective.aspx</span>
<span style="color: #666666; font-style: italic;">#     http://openxmldeveloper.org/forums/thread/597.aspx</span>
<span style="color: #666666; font-style: italic;">#     Hugo Mildenberger for a patch submitted on 08/31/2010</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#    This program is free software: you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#    it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#    the Free Software Foundation, either version 3 of the License, or</span>
<span style="color: #666666; font-style: italic;">#    (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#    This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#    GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#    You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#     Release notes:</span>
<span style="color: #666666; font-style: italic;">#         1.0 (2009/12/18) -- First release available to the public</span>
<span style="color: #666666; font-style: italic;">#         1.1 (2010/01/12) -- Improved date handling routine to look for all common date formats in Excel.</span>
<span style="color: #666666; font-style: italic;">#         1.2 (2010/08/31) -- Now uses /tmp, supports whitespace in filename, has a --help switch</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.2&quot;</span>
<span style="color: #007800;">tmpdir</span>=<span style="color: #ff0000;">&quot;/tmp&quot;</span>
<span style="color: #007800;">overwrite</span>=<span style="color: #ff0000;">&quot;No&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> usage <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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
  Usage:  $(basename $0) [-h|--help] [-c|--copyleft] [-d|--debug] [-v|--version] [-o|--overwrite]
                         [-t|--tmpdir] tempdir -x[|--xlsx] filename
          -h, --help             display this text
          -c, --copyleft         display copyright
          -d, --debug            show command output 
          -o, --overwrite        overwrite already existing output files
          -v, --version          output version of this script 
          -t, --tmpdir dirname   specify where temporary files should be created (currently in &quot;${tmpdir}&quot;) 
          -x, --xlsx filename    name of input file
&nbsp;
For those of us converting huge spreadsheets (or a lot of them):
Create a ramdisk on OSX with the following code:
NUMSECTORS=262144
# 64mb = 131072 , 128mb = 262144 , 256mb = 524288 , 512mb = 1048576 , 1gb = 2097152 
mydev=\$(hdid -nomount ram://\$NUMSECTORS) 
newfs_hfs \$mydev 
[[ -d ~/sdb ]] || mkdir ~/sdb 
mount -t hfs \$mydev ~/sdb
&nbsp;
Then, use this mounted ramdisk for your temporary storage for $0.
$0 -t ~/sdb -x filename
On ubuntu, just use /dev/shm
$0 -t /dev/shm -x filename
&nbsp;
Thanks to Hugo Mildeberger for cleaning up the temp dir code to make this work.
EOS</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  usage
  <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: #000000; font-weight: bold;">for</span> arg 
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;&quot;</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$arg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #666666; font-style: italic;">#translate --gnu-long-options to -g (short options) </span>
    --copyleft<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-c &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --xlsx<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-x &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --debug<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-d &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --version<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-v &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --overwrite<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-o &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --tmpdir<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-t &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    --help<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-h &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #666666; font-style: italic;">#pass through anything else</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">leftchar</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #000000; font-weight: bold;">%</span>1.1s <span style="color: #ff0000;">&quot;<span style="color: #007800;">$arg</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</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: #ff0000;">&quot;<span style="color: #007800;">$leftchar</span>&quot;</span> == <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
      <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span><span style="color: #007800;">${delim}</span><span style="color: #007800;">${arg}</span><span style="color: #007800;">${delim}</span> &quot;</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#Reset the positional parameters to the short options</span>
<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$args</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;:cdhot:vx:&quot;</span> option <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #800000;">${option}</span> <span style="color: #000000; font-weight: bold;">in</span>
    c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">650</span> <span style="color: #ff0000;">&quot;$0&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">621</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: #666666; font-style: italic;">#copyleft</span>
       <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
    d<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span> <span style="color: #666666; font-style: italic;">#debug</span>
       <span style="color: #007800;">debug</span>=<span style="color: #c20cb9; font-weight: bold;">true</span><span style="color: #000000; font-weight: bold;">;;</span>
    h<span style="color: #7a0874; font-weight: bold;">&#41;</span> usage; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">;;</span>
    o<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">overwrite</span>=<span style="color: #ff0000;">&quot;Yes&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    t<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">tmpdir</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span> <span style="color: #666666; font-style: italic;">#temporary directory</span>
    v<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$version</span>; <span style="color: #7a0874; font-weight: bold;">exit</span><span style="color: #000000; font-weight: bold;">;;</span> <span style="color: #666666; font-style: italic;">#version</span>
    x<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">filename</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${OPTARG}</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span> <span style="color: #666666; font-style: italic;">#xlsx</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #007800;">$OPTARG</span><span style="color: #ff0000;">&quot;'&quot;</span> is an unrecognized option<span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$0: using tmpdir <span style="color: #007800;">${tmpdir}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</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;">${tmpdir}</span>&quot;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</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;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
  the directory ${tmpdir} does not exist. Use, e.g.,  --tempdir '.' to use current directory
EOS</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filename</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  usage
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
  Filename is required.
EOS</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filename</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</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;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
  File not found.
EOS</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#find out what inode we're in</span>
<span style="color: #007800;">appdir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$appdir</span>&quot;</span> == <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">appdir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">curdir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">appname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#set up some platform specific utilities</span>
<span style="color: #007800;">gnused</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">sed</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">platform</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${platform}</span>&quot;</span> == <span style="color: #ff0000;">&quot;Darwin&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">gnused</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gsed
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$gnused</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Can't find a copy of GNU sed&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Make a working directory based on the filename</span>
<span style="color: #007800;">filtered</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filename</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\.xlsx$//g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[[:space:]]/_/g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">dirname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">mktemp</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmpdir}</span>/<span style="color: #007800;">$filtered</span>.XXXXXXXXXXXXXX.tmp&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #666666; font-style: italic;">#copy the source file into it</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filename</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dirname</span>&quot;</span>
<span style="color: #666666; font-style: italic;">#get in there and push</span>
<span style="color: #7a0874; font-weight: bold;">pushd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dirname</span>&quot;</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
&nbsp;
<span style="color: #007800;">workfilename</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(basename &quot;$filename&quot;)</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># Unpack the xlsx file</span>
<span style="color: #c20cb9; font-weight: bold;">unzip</span> <span style="color: #660033;">-q</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$workfilename</span>&quot;</span>
<span style="color: #666666; font-style: italic;">#Did we get the expected structure?</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: #660033;">-d</span> <span style="color: #ff0000;">&quot;xl&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$filename</span> is not an xlsx format <span style="color: #c20cb9; font-weight: bold;">file</span>
  <span style="color: #7a0874; font-weight: bold;">popd</span>
  <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dirname</span>&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: #666666; font-style: italic;">#Make a sqlite3 database to do some relational work</span>
<span style="color: #007800;">sdbname</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(pwd)</span>/<span style="color: #007800;">${filtered}</span>.sdb&quot;</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: #c20cb9; font-weight: bold;">hostname</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> == <span style="color: #ff0000;">&quot;wsmkroybal.javelin.pvt&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">sdbname</span>=<span style="color: #ff0000;">&quot;/Users/kroybal/sdb/<span style="color: #007800;">${filtered}</span>.sdb&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${filtered}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Create an SQL based string table</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE shared_strings (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  value string);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>  <span style="color: #666666; font-style: italic;">#The first access of the db will create the file</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#turn the starting tags directly into newline</span>
<span style="color: #007800;">newline</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'\n\r'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#turn the xml for shared strings into sqlite sql</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.xml&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;rPr&gt;.*&lt;\/rPr&gt;//g&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>  <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span>
<span style="color: #666666; font-style: italic;">#blow away embedded garbage</span>
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;r&gt;&lt;t&gt;.&lt;\/t&gt;&lt;\/r&gt;//g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;si&gt;/\<span style="color: #000099; font-weight: bold;">\$</span>newline/g&quot;</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span> 
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;\/t&gt;.$//g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;t&gt;//g&quot;</span>  <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/^[:space:]]*$/d&quot;</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span> 
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;t xml:space=<span style="color: #000099; font-weight: bold;">\&quot;</span>preserve<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;//g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;r&gt;//g'</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span> 
<span style="color: #666666; font-style: italic;">#remove any non-printable characters, the xml tag line, and the DTD</span>
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/[^[:graph:] ]*//g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;1,2d&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/'/''/g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/amp;//g'</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span>
<span style="color: #666666; font-style: italic;">#blow off any formatting junk after the closing tag</span>
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/&lt;\/t&gt;.*$//&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/^$/d&quot;</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span>
<span style="color: #666666; font-style: italic;">#trim the result</span>
<span style="color: #666666; font-style: italic;">#sed -i '' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' &quot;xl/sharedStrings.sed&quot;</span>
<span style="color: #666666; font-style: italic;">#make a sql statement out of the result</span>
<span style="color: #007800;">$gnused</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/^/INSERT INTO shared_strings (value) VALUES ('/&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/$/');/&quot;</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span>
<span style="color: #666666; font-style: italic;">#load the stringtable</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #ff0000;">&quot;xl/sharedStrings.sed&quot;</span>
&nbsp;
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE INDEX idx_ss ON shared_strings(id,value);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE sheets (
id INTEGER PRIMARY KEY,
name varchar(200),
ordinal integer,
rid integer);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#make an xslt file to import the sheet names</span>
<span style="color: #007800;">xsl</span>=<span style="color: #ff0000;">&quot;&lt;xsl:stylesheet version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> xmlns:xsl=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/1999/XSL/Transform<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
&lt;xsl:output method=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>sheets<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
  &lt;xsl:apply-templates select=<span style="color: #000099; font-weight: bold;">\&quot;</span>sheet<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>sheet<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
    INSERT INTO sheets(name,ordinal,rid) VALUES ('&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>translate(@name,&amp;quot;'&amp;quot;,&amp;quot;&amp;quot;)<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;',&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>@sheetId<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;,&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>@rid<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;); 
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;&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;">$xsl</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;xl/sheets.xsl&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#make a simpler xml file to parse</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;xl/workbook.xml&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/.*&lt;sheets/&lt;sheets/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/r:id/rid/g'</span> <span style="color: #000000; font-weight: bold;">|</span>
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;\/sheets&gt;.*/&lt;\/sheets&gt;/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&quot;rId/&quot;/g'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;xl/sheets.xml&quot;</span>
<span style="color: #666666; font-style: italic;">#import the sheet names</span>
xsltproc <span style="color: #ff0000;">&quot;xl/sheets.xsl&quot;</span> <span style="color: #ff0000;">&quot;xl/sheets.xml&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">#import the format styles</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE fmt_data (
id INTEGER PRIMARY KEY,
numfmtid integer,
formatcode varchar(200));&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#import the format data</span>
<span style="color: #007800;">fmtxsl</span>=<span style="color: #ff0000;">&quot;&lt;xsl:stylesheet version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> xmlns:xsl=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/1999/XSL/Transform<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
&lt;xsl:output method=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>numFmts<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
  &lt;xsl:apply-templates select=<span style="color: #000099; font-weight: bold;">\&quot;</span>numFmt<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>numFmt<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
    INSERT INTO fmt_data(numfmtid,formatcode) VALUES ('&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>@numFmtId<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;','&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>@formatCode<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;'); 
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#create an xsl stylesheet for formats</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;">$fmtxsl</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">'xl/fmt.xsl'</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#simplify the input file</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;xl/styles.xml&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^.*&lt;numFmts/&lt;numFmts/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;\/numFmts&gt;.*/&lt;\/numFmts&gt;/'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;xl/fmts.xml&quot;</span>
<span style="color: #666666; font-style: italic;">#import the formats</span>
xsltproc <span style="color: #ff0000;">&quot;xl/fmt.xsl&quot;</span> <span style="color: #ff0000;">&quot;xl/fmts.xml&quot;</span>  <span style="color: #000000; font-weight: bold;">|</span> sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">#associate the formats to cells</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE fmt2cell_data (
id INTEGER PRIMARY KEY,
numfmtid integer);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#now import the format 2 field mapping table</span>
<span style="color: #007800;">fmtxsl</span>=<span style="color: #ff0000;">&quot;&lt;xsl:stylesheet version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> xmlns:xsl=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/1999/XSL/Transform<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
&lt;xsl:output method=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>cellXfs<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
  &lt;xsl:apply-templates select=<span style="color: #000099; font-weight: bold;">\&quot;</span>xf<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=<span style="color: #000099; font-weight: bold;">\&quot;</span>xf<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
    INSERT INTO fmt2cell_data(numfmtid) VALUES ('&lt;xsl:value-of select=<span style="color: #000099; font-weight: bold;">\&quot;</span>@numFmtId<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;'); 
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#create an xsl stylesheet for formats</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;">$fmtxsl</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">'xl/fmt2cell.xsl'</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#simplify the input file</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;xl/styles.xml&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^.*&lt;cellXfs/&lt;cellXfs/'</span> <span style="color: #000000; font-weight: bold;">|</span>
    <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;\/cellXfs&gt;.*/&lt;\/cellXfs&gt;/'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;xl/fmt2cell.xml&quot;</span>
<span style="color: #666666; font-style: italic;">#import the mapping</span>
xsltproc <span style="color: #ff0000;">&quot;xl/fmt2cell.xsl&quot;</span> <span style="color: #ff0000;">&quot;xl/fmt2cell.xml&quot;</span>  <span style="color: #000000; font-weight: bold;">|</span> sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#delete the formats that obviously have nothing to do with dates.</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;DELETE FROM fmt2cell_data WHERE numfmtid=0;&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#create a table of known date formats</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE date_formats (
id INTEGER PRIMARY KEY,
format varchar(500));&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Insert all the date formats we know about</span>
<span style="color: #007800;">insert</span>=<span style="color: #ff0000;">&quot;INSERT INTO <span style="color: #000099; font-weight: bold;">\&quot;</span>date_formats<span style="color: #000099; font-weight: bold;">\&quot;</span> (format) VALUES&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-F800]dddd\,\ mmmm\ dd\,\ yyyy');
<span style="color: #007800;">$insert</span> ('m/d;@');
<span style="color: #007800;">$insert</span> ('mmm\ d');
<span style="color: #007800;">$insert</span> ('m/d/yy;@');
<span style="color: #007800;">$insert</span> ('mm/dd/yy;@');
<span style="color: #007800;">$insert</span> ('m/d/yyyy;@');
<span style="color: #007800;">$insert</span> ('m/d/yy\ h:mm;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]mmmmm;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]d\-mmm;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]mmm\-yy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]mmmm\-yy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]mmmmm\-yy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]d\-mmm\-yy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]d\-mmm\-yyyy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]mmmm\ d\,\ yyyy;@');
<span style="color: #007800;">$insert</span> ('[<span style="color: #000099; font-weight: bold;">\$</span>-409]m/d/yy\ h:mm\ AM/PM;@');
--<span style="color: #007800;">$insert</span> ('_(* #,##0_);_(* \(#,##0\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(* #,##0_);_(* \(#,##0\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(* #,##0.0_);_(* \(#,##0.0\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>?_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(* #,##0.0_);_(* \(#,##0.0\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(* #,##0.00_);_(* \(#,##0.00\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(* #,##0.0000_);_(* \(#,##0.0000\);_(* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* #,##0.00_);_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* \(#,##0.00\);_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
--<span style="color: #007800;">$insert</span> ('_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* #,##0.000_);_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* \(#,##0.000\);_(<span style="color: #000099; font-weight: bold;">\&quot;</span>$<span style="color: #000099; font-weight: bold;">\&quot;</span>* <span style="color: #000099; font-weight: bold;">\&quot;</span>-<span style="color: #000099; font-weight: bold;">\&quot;</span>??_);_(@_)');
&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#see if anything matches the dates we know about</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE fmt_data SET formatcode = 'date' where formatcode IN 
  (SELECT format FROM date_formats);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#propagate the formats from the fmt_data table</span>
<span style="color: #666666; font-style: italic;"># to the fmt2cell_data table</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;REPLACE INTO fmt2cell_data (id,numfmtid) 
      select fc.id, fd.formatcode 
      FROM fmt2cell_data fc INNER JOIN fmt_data fd 
      ON fc.numfmtid = fd.numfmtid
      WHERE fd.formatcode='date';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE cell_data (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  sheet varchar(255),
  cell varchar(200),
  style integer,
  type varchar(3),
  value varchar(200),
  row integer,
  col varchar(20)
);&quot;</span> 
<span style="color: #666666; font-style: italic;"># Leftovers from date calculation improvements</span>
<span style="color: #666666; font-style: italic;">#  a integer,</span>
<span style="color: #666666; font-style: italic;">#  b integer,</span>
<span style="color: #666666; font-style: italic;">#  c integer,</span>
<span style="color: #666666; font-style: italic;">#  d integer,</span>
<span style="color: #666666; font-style: italic;">#  e integer,</span>
<span style="color: #666666; font-style: italic;">#  f integer,</span>
<span style="color: #666666; font-style: italic;">#  g integer,</span>
<span style="color: #666666; font-style: italic;">#  y integer,</span>
<span style="color: #666666; font-style: italic;">#  m integer,</span>
<span style="color: #666666; font-style: italic;">#  day integer</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#extract the data for each sheet to sqlite</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> xl<span style="color: #000000; font-weight: bold;">/</span>worksheets<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#xsltproc requires the style sheet as a file</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">27</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$appdir</span>/<span style="color: #007800;">$appname</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> data.xsl
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.xml
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #666666; font-style: italic;">#Remove the formatting we can't read anyway to make the xslt parser simpler. </span>
  <span style="color: #666666; font-style: italic;"># remove any trailing lines after the sheetData</span>
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/.*&lt;sheetData/&lt;sheetData/'</span> <span style="color: #000000; font-weight: bold;">|</span>
    <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;\/sheetData&gt;.*/&lt;\/sheetData&gt;/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'3,$d'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>.data&quot;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">#translate the data into sqlite INSERT statements</span>
  <span style="color: #666666; font-style: italic;"># 3 copies of sed streaming are an intentional speed enhancement.</span>
  xsltproc data.xsl <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>.data&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
      <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/'/''/g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/|/'/g&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&amp;amp;/&amp;/g'</span> <span style="color: #000000; font-weight: bold;">|</span>
      <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;/'');[[:space:]]*$/d&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># &gt; &quot;${file}.sql&quot;</span>
<span style="color: #666666; font-style: italic;"># &lt; &quot;${file}.sql&quot;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">#Add the sheet name to the data we just imported</span>
  <span style="color: #007800;">bname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> .xml <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/'//g&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[[:alpha:]]*//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET sheet=(SELECT name FROM sheets WHERE rid = <span style="color: #007800;">${bname}</span>)
       WHERE sheet is null;&quot;</span>
  sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#remove any blank cells</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;DELETE FROM cell_data WHERE value = '';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#index the type column</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE INDEX idx_cd ON cell_data(type);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#shared string table is zero based in file, 1 based in sdb</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value=value+1 WHERE type='s';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#update the cells with the string data</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;REPLACE INTO cell_data(id,value,sheet,cell,style,type,row,col) 
    SELECT cd.id, ss.value, cd.sheet, cd.cell, 'str', '', cd.row, cd.col 
    FROM shared_strings ss INNER JOIN cell_data cd ON ss.id = cd.value 
    WHERE cd.type = 's';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#basic data formats with id&lt;=40 that are dates.</span>
<span style="color: #666666; font-style: italic;">#  these are not supplied in the xlsx file</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE fmt2cell_data SET numfmtid = 'date'
      WHERE numfmtid IN (14,15,16);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Other subformats that are also dates.</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;REPLACE INTO cell_data (id,value,sheet,cell,style,type,row,col) 
  SELECT cd.id, cd.value,cd.sheet,cd.cell,'2','d',cd.row,cd.col
  FROM cell_data cd INNER JOIN fmt2cell_data fc ON cd.style+1=fc.id
  WHERE fc.numfmtid = 'date' and cd.style &lt;&gt; '2' 
  AND cd.type='' AND cd.value&lt;&gt;'';&quot;</span>;
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Fix the Y1900 leap year bug</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value='1900-02-29 00:00:00',style='s' 
     WHERE value=60 AND style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Other dates less than 60 are off by 1</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value=value+1 WHERE value &lt; 60 AND style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#convert the Julian serial to date</span>
<span style="color: #666666; font-style: italic;"># add days to convert to unix epoch</span>
<span style="color: #666666; font-style: italic;"># convert epoch to ISO date as text</span>
<span style="color: #666666; font-style: italic;"># end up with YYYY-MM-DD</span>
<span style="color: #666666; font-style: italic;">#Much easier and more reliable</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value=datetime(value+2415017.5) 
     WHERE style='2' and value &lt;&gt; '';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;A&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #666666; font-style: italic;">#old school date calculation</span>
<span style="color: #666666; font-style: italic;"># this code is a non-buggy implementation of the</span>
<span style="color: #666666; font-style: italic;">#  buggy code found at</span>
<span style="color: #666666; font-style: italic;">#  http://www.codeproject.com/KB/datetime/exceldmy.aspx?print=true</span>
<span style="color: #666666; font-style: italic;"># The basic idea here is to convert the date to a unix epoch</span>
<span style="color: #666666; font-style: italic;">#  add some days to make sure that 1970-01-01 &lt; date &lt; 2038-01-01</span>
<span style="color: #666666; font-style: italic;">#  because MS date functions only work properly within that range</span>
<span style="color: #666666; font-style: italic;">#  then re-implement MS date math logic to find the date</span>
<span style="color: #666666; font-style: italic;">#  then subtract the bias in years from the date.</span>
<span style="color: #666666; font-style: italic;"># We don't do things like that in Linux land.</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET a=value+68569+2415019 WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET b=cast((4*a)/146097.0 as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET c=a-((146097*b+3)/4) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET d=cast((4000*(c+1))/1461001.0 as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET e=(c-cast(1461.0*d/4 as integer)+31 WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET f=cast((80*e)/2447 as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET g=cast(f/11 as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET day=e-cast((2447.0*f)/80 as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET m=cast(f+2.0-(12.0*g) as integer) WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET y=100*(b-49)+d+g WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Finally!  We have a date!</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data 
     SET value=y || '-' || m || '-' || day, style=''  WHERE style='2';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#don't show nulls as '-' (dash)</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value='', style=''  WHERE style='3';&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#get the row numbers as integers</span>
<span style="color: #666666; font-style: italic;">#Get the column indices as letters [A-ZZ]</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data 
     SET row=CAST(trim(cell,'ABCDEFGHIJKLMNOPQRSTUVWXYZ') as int),
         col=trim(cell,'0123456789');&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#blow away CRLF in the values</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE cell_data SET value=replace(value,x'0d','');&quot;</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span> UPDATE cell_data SET value=replace(value,x'0a','');&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#set up column list from A-ZZ collated in spreadsheet order</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE TABLE columns ( id integer primary key, title varchar(3));&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #666666; font-style: italic;">#create A-Z</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">i</span>=<span style="color: #000000;">65</span>;i<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000;">90</span>;i++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
     <span style="color: #666666; font-style: italic;">#convert ascii value to char</span>
     <span style="color: #007800;">char</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;\<span style="color: #000099; font-weight: bold;">\$</span>(printf &quot;</span><span style="color: #000000; font-weight: bold;">%</span>03o<span style="color: #ff0000;">&quot; <span style="color: #007800;">$i</span>)&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #666666; font-style: italic;">#insert into db </span>
     <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;INSERT INTO columns (title) VALUES ('<span style="color: #007800;">$char</span>');&quot;</span>
     sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span> 
<span style="color: #666666; font-style: italic;"># Create AA-ZZ</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">i</span>=<span style="color: #000000;">1</span>;i<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000;">26</span>;i++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;INSERT INTO columns (title) 
       SELECT (SELECT title FROM columns WHERE id=<span style="color: #007800;">$i</span>) || title 
       FROM columns where id &lt;= 26;&quot;</span>
  sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#index the sheet name</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE INDEX idx_cd_sheet ON cell_data(sheet);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># and the sheet with col</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE INDEX idx_cd_sheet_col ON cell_data(sheet,col);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># and the sheet with row</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;CREATE INDEX idx_cd_sheet_row ON cell_data(sheet,row);&quot;</span>
sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span>
<span style="color: #007800;">newline</span>=<span style="color: #ff0000;">&quot;
&quot;</span>
<span style="color: #666666; font-style: italic;">#Change the internal separator to CRLF</span>
<span style="color: #007800;">IFS</span>=$<span style="color: #ff0000;">'\n'</span>
<span style="color: #666666; font-style: italic;">#walk the table and output the results as csv files.</span>
<span style="color: #666666; font-style: italic;"># for each sheet (csv file name); for each row, for each value</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;SELECT sheet FROM cell_data group by sheet order by sheet;&quot;</span>
<span style="color: #007800;">sheets</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> sheet <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$sheets</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #666666; font-style: italic;">#the columns.id field now collates the columns in spreadsheet order</span>
  <span style="color: #666666; font-style: italic;"># all we need to know is the maximum number of columns per sheet</span>
  <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;SELECT c.id FROM columns c INNER JOIN cell_data d ON c.title = d.col 
        WHERE sheet='<span style="color: #007800;">$sheet</span>' ORDER by c.id DESC limit 1;&quot;</span>
  <span style="color: #007800;">maxcol</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">#no single quotes in filename</span>
  <span style="color: #007800;">csv</span>=<span style="color: #800000;">${sheet//\'/}</span>
  <span style="color: #007800;">csv</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${curdir}</span>/<span style="color: #007800;">${filtered}</span>_<span style="color: #007800;">${csv// /_}</span>.csv&quot;</span>
  <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: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${csv}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> x<span style="color: #ff0000;">&quot;<span style="color: #007800;">${overwrite}</span>&quot;</span> == <span style="color: #ff0000;">&quot;xYes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> 
       <span style="color: #666666; font-style: italic;">#echo &quot;removing preexisting output file ${csv}&quot;</span>
       <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${csv}</span>&quot;</span>
  <span style="color: #000000; font-weight: bold;">else</span>
       <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;output file <span style="color: #007800;">${csv}</span> already exists and --overwrite option not given, exiting ...&quot;</span>
       <span style="color: #666666; font-style: italic;">#return to the invocation inode</span>
       <span style="color: #7a0874; font-weight: bold;">popd</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
&nbsp;
       <span style="color: #666666; font-style: italic;">#clean up the temp folder</span>
       <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$debug</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</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: #ff0000;">&quot;<span style="color: #007800;">$dirname</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;">#get the rows for the sheet</span>
  <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;SELECT row FROM cell_data WHERE sheet='<span style="color: #007800;">$sheet</span>' 
       GROUP BY row ORDER BY row;&quot;</span>
  <span style="color: #007800;">rows</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">for</span> row <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$rows</span>
  <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #666666; font-style: italic;">#make sure we have a field represented for every column, even if it's empty</span>
    <span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;SELECT d.value FROM columns c left join cell_data d 
          ON c.title = d.col AND d.sheet='<span style="color: #007800;">$sheet</span>' AND d.row=<span style="color: #007800;">$row</span>
          WHERE c.id &lt;= <span style="color: #007800;">$maxcol</span>;&quot;</span>
    sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #666666; font-style: italic;">#extract the data for the row</span>
        <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[&amp;]lt;/&lt;/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[&amp;]gt;/&gt;/g'</span>   <span style="color: #000000; font-weight: bold;">|</span>
        <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&quot;/&quot;&quot;/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^/&quot;/'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/$/&quot;/'</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #666666; font-style: italic;">#escape embedded quotes</span>
        <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #ff0000;">','</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/,$//&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$csv</span>&quot;</span> <span style="color: #666666; font-style: italic;">#convert to csv </span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${csv}</span>&quot;</span>
  <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<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: #c20cb9; font-weight: bold;">hostname</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> == <span style="color: #ff0000;">&quot;wsmkroybal.javelin.pvt&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sdbname</span>&quot;</span> .
&nbsp;
<span style="color: #666666; font-style: italic;">#return to the invocation inode</span>
<span style="color: #7a0874; font-weight: bold;">popd</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
&nbsp;
<span style="color: #666666; font-style: italic;">#clean up the temp folder</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$debug</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</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: #ff0000;">&quot;<span style="color: #007800;">$dirname</span>&quot;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">#clean end</span>
<span style="color: #7a0874; font-weight: bold;">exit</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#                     GNU GENERAL PUBLIC LICENSE</span>
<span style="color: #666666; font-style: italic;">#                        Version 3, 29 June 2007</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#  Copyright (C) 2007 Free Software Foundation, Inc. &lt;http://fsf.org/&gt;</span>
<span style="color: #666666; font-style: italic;">#  Everyone is permitted to copy and distribute verbatim copies</span>
<span style="color: #666666; font-style: italic;">#  of this license document, but changing it is not allowed.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#                             Preamble</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The GNU General Public License is a free, copyleft license for</span>
<span style="color: #666666; font-style: italic;"># software and other kinds of works.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The licenses for most software and other practical works are designed</span>
<span style="color: #666666; font-style: italic;"># to take away your freedom to share and change the works.  By contrast,</span>
<span style="color: #666666; font-style: italic;"># the GNU General Public License is intended to guarantee your freedom to</span>
<span style="color: #666666; font-style: italic;"># share and change all versions of a program--to make sure it remains free</span>
<span style="color: #666666; font-style: italic;"># software for all its users.  We, the Free Software Foundation, use the</span>
<span style="color: #666666; font-style: italic;"># GNU General Public License for most of our software; it applies also to</span>
<span style="color: #666666; font-style: italic;"># any other work released this way by its authors.  You can apply it to</span>
<span style="color: #666666; font-style: italic;"># your programs, too.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   When we speak of free software, we are referring to freedom, not</span>
<span style="color: #666666; font-style: italic;"># price.  Our General Public Licenses are designed to make sure that you</span>
<span style="color: #666666; font-style: italic;"># have the freedom to distribute copies of free software (and charge for</span>
<span style="color: #666666; font-style: italic;"># them if you wish), that you receive source code or can get it if you</span>
<span style="color: #666666; font-style: italic;"># want it, that you can change the software or use pieces of it in new</span>
<span style="color: #666666; font-style: italic;"># free programs, and that you know you can do these things.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   To protect your rights, we need to prevent others from denying you</span>
<span style="color: #666666; font-style: italic;"># these rights or asking you to surrender the rights.  Therefore, you have</span>
<span style="color: #666666; font-style: italic;"># certain responsibilities if you distribute copies of the software, or if</span>
<span style="color: #666666; font-style: italic;"># you modify it: responsibilities to respect the freedom of others.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   For example, if you distribute copies of such a program, whether</span>
<span style="color: #666666; font-style: italic;"># gratis or for a fee, you must pass on to the recipients the same</span>
<span style="color: #666666; font-style: italic;"># freedoms that you received.  You must make sure that they, too, receive</span>
<span style="color: #666666; font-style: italic;"># or can get the source code.  And you must show them these terms so they</span>
<span style="color: #666666; font-style: italic;"># know their rights.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Developers that use the GNU GPL protect your rights with two steps:</span>
<span style="color: #666666; font-style: italic;"># (1) assert copyright on the software, and (2) offer you this License</span>
<span style="color: #666666; font-style: italic;"># giving you legal permission to copy, distribute and/or modify it.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   For the developers' and authors' protection, the GPL clearly explains</span>
<span style="color: #666666; font-style: italic;"># that there is no warranty for this free software.  For both users' and</span>
<span style="color: #666666; font-style: italic;"># authors' sake, the GPL requires that modified versions be marked as</span>
<span style="color: #666666; font-style: italic;"># changed, so that their problems will not be attributed erroneously to</span>
<span style="color: #666666; font-style: italic;"># authors of previous versions.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Some devices are designed to deny users access to install or run</span>
<span style="color: #666666; font-style: italic;"># modified versions of the software inside them, although the manufacturer</span>
<span style="color: #666666; font-style: italic;"># can do so.  This is fundamentally incompatible with the aim of</span>
<span style="color: #666666; font-style: italic;"># protecting users' freedom to change the software.  The systematic</span>
<span style="color: #666666; font-style: italic;"># pattern of such abuse occurs in the area of products for individuals to</span>
<span style="color: #666666; font-style: italic;"># use, which is precisely where it is most unacceptable.  Therefore, we</span>
<span style="color: #666666; font-style: italic;"># have designed this version of the GPL to prohibit the practice for those</span>
<span style="color: #666666; font-style: italic;"># products.  If such problems arise substantially in other domains, we</span>
<span style="color: #666666; font-style: italic;"># stand ready to extend this provision to those domains in future versions</span>
<span style="color: #666666; font-style: italic;"># of the GPL, as needed to protect the freedom of users.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Finally, every program is threatened constantly by software patents.</span>
<span style="color: #666666; font-style: italic;"># States should not allow patents to restrict development and use of</span>
<span style="color: #666666; font-style: italic;"># software on general-purpose computers, but in those that do, we wish to</span>
<span style="color: #666666; font-style: italic;"># avoid the special danger that patents applied to a free program could</span>
<span style="color: #666666; font-style: italic;"># make it effectively proprietary.  To prevent this, the GPL assures that</span>
<span style="color: #666666; font-style: italic;"># patents cannot be used to render the program non-free.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The precise terms and conditions for copying, distribution and</span>
<span style="color: #666666; font-style: italic;"># modification follow.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#                        TERMS AND CONDITIONS</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   0. Definitions.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   &quot;This License&quot; refers to version 3 of the GNU General Public License.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   &quot;Copyright&quot; also means copyright-like laws that apply to other kinds of</span>
<span style="color: #666666; font-style: italic;"># works, such as semiconductor masks.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   &quot;The Program&quot; refers to any copyrightable work licensed under this</span>
<span style="color: #666666; font-style: italic;"># License.  Each licensee is addressed as &quot;you&quot;.  &quot;Licensees&quot; and</span>
<span style="color: #666666; font-style: italic;"># &quot;recipients&quot; may be individuals or organizations.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   To &quot;modify&quot; a work means to copy from or adapt all or part of the work</span>
<span style="color: #666666; font-style: italic;"># in a fashion requiring copyright permission, other than the making of an</span>
<span style="color: #666666; font-style: italic;"># exact copy.  The resulting work is called a &quot;modified version&quot; of the</span>
<span style="color: #666666; font-style: italic;"># earlier work or a work &quot;based on&quot; the earlier work.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A &quot;covered work&quot; means either the unmodified Program or a work based</span>
<span style="color: #666666; font-style: italic;"># on the Program.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   To &quot;propagate&quot; a work means to do anything with it that, without</span>
<span style="color: #666666; font-style: italic;"># permission, would make you directly or secondarily liable for</span>
<span style="color: #666666; font-style: italic;"># infringement under applicable copyright law, except executing it on a</span>
<span style="color: #666666; font-style: italic;"># computer or modifying a private copy.  Propagation includes copying,</span>
<span style="color: #666666; font-style: italic;"># distribution (with or without modification), making available to the</span>
<span style="color: #666666; font-style: italic;"># public, and in some countries other activities as well.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   To &quot;convey&quot; a work means any kind of propagation that enables other</span>
<span style="color: #666666; font-style: italic;"># parties to make or receive copies.  Mere interaction with a user through</span>
<span style="color: #666666; font-style: italic;"># a computer network, with no transfer of a copy, is not conveying.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   An interactive user interface displays &quot;Appropriate Legal Notices&quot;</span>
<span style="color: #666666; font-style: italic;"># to the extent that it includes a convenient and prominently visible</span>
<span style="color: #666666; font-style: italic;"># feature that (1) displays an appropriate copyright notice, and (2)</span>
<span style="color: #666666; font-style: italic;"># tells the user that there is no warranty for the work (except to the</span>
<span style="color: #666666; font-style: italic;"># extent that warranties are provided), that licensees may convey the</span>
<span style="color: #666666; font-style: italic;"># work under this License, and how to view a copy of this License.  If</span>
<span style="color: #666666; font-style: italic;"># the interface presents a list of user commands or options, such as a</span>
<span style="color: #666666; font-style: italic;"># menu, a prominent item in the list meets this criterion.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   1. Source Code.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The &quot;source code&quot; for a work means the preferred form of the work</span>
<span style="color: #666666; font-style: italic;"># for making modifications to it.  &quot;Object code&quot; means any non-source</span>
<span style="color: #666666; font-style: italic;"># form of a work.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A &quot;Standard Interface&quot; means an interface that either is an official</span>
<span style="color: #666666; font-style: italic;"># standard defined by a recognized standards body, or, in the case of</span>
<span style="color: #666666; font-style: italic;"># interfaces specified for a particular programming language, one that</span>
<span style="color: #666666; font-style: italic;"># is widely used among developers working in that language.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The &quot;System Libraries&quot; of an executable work include anything, other</span>
<span style="color: #666666; font-style: italic;"># than the work as a whole, that (a) is included in the normal form of</span>
<span style="color: #666666; font-style: italic;"># packaging a Major Component, but which is not part of that Major</span>
<span style="color: #666666; font-style: italic;"># Component, and (b) serves only to enable use of the work with that</span>
<span style="color: #666666; font-style: italic;"># Major Component, or to implement a Standard Interface for which an</span>
<span style="color: #666666; font-style: italic;"># implementation is available to the public in source code form.  A</span>
<span style="color: #666666; font-style: italic;"># &quot;Major Component&quot;, in this context, means a major essential component</span>
<span style="color: #666666; font-style: italic;"># (kernel, window system, and so on) of the specific operating system</span>
<span style="color: #666666; font-style: italic;"># (if any) on which the executable work runs, or a compiler used to</span>
<span style="color: #666666; font-style: italic;"># produce the work, or an object code interpreter used to run it.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The &quot;Corresponding Source&quot; for a work in object code form means all</span>
<span style="color: #666666; font-style: italic;"># the source code needed to generate, install, and (for an executable</span>
<span style="color: #666666; font-style: italic;"># work) run the object code and to modify the work, including scripts to</span>
<span style="color: #666666; font-style: italic;"># control those activities.  However, it does not include the work's</span>
<span style="color: #666666; font-style: italic;"># System Libraries, or general-purpose tools or generally available free</span>
<span style="color: #666666; font-style: italic;"># programs which are used unmodified in performing those activities but</span>
<span style="color: #666666; font-style: italic;"># which are not part of the work.  For example, Corresponding Source</span>
<span style="color: #666666; font-style: italic;"># includes interface definition files associated with source files for</span>
<span style="color: #666666; font-style: italic;"># the work, and the source code for shared libraries and dynamically</span>
<span style="color: #666666; font-style: italic;"># linked subprograms that the work is specifically designed to require,</span>
<span style="color: #666666; font-style: italic;"># such as by intimate data communication or control flow between those</span>
<span style="color: #666666; font-style: italic;"># subprograms and other parts of the work.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The Corresponding Source need not include anything that users</span>
<span style="color: #666666; font-style: italic;"># can regenerate automatically from other parts of the Corresponding</span>
<span style="color: #666666; font-style: italic;"># Source.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The Corresponding Source for a work in source code form is that</span>
<span style="color: #666666; font-style: italic;"># same work.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   2. Basic Permissions.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   All rights granted under this License are granted for the term of</span>
<span style="color: #666666; font-style: italic;"># copyright on the Program, and are irrevocable provided the stated</span>
<span style="color: #666666; font-style: italic;"># conditions are met.  This License explicitly affirms your unlimited</span>
<span style="color: #666666; font-style: italic;"># permission to run the unmodified Program.  The output from running a</span>
<span style="color: #666666; font-style: italic;"># covered work is covered by this License only if the output, given its</span>
<span style="color: #666666; font-style: italic;"># content, constitutes a covered work.  This License acknowledges your</span>
<span style="color: #666666; font-style: italic;"># rights of fair use or other equivalent, as provided by copyright law.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may make, run and propagate covered works that you do not</span>
<span style="color: #666666; font-style: italic;"># convey, without conditions so long as your license otherwise remains</span>
<span style="color: #666666; font-style: italic;"># in force.  You may convey covered works to others for the sole purpose</span>
<span style="color: #666666; font-style: italic;"># of having them make modifications exclusively for you, or provide you</span>
<span style="color: #666666; font-style: italic;"># with facilities for running those works, provided that you comply with</span>
<span style="color: #666666; font-style: italic;"># the terms of this License in conveying all material for which you do</span>
<span style="color: #666666; font-style: italic;"># not control copyright.  Those thus making or running the covered works</span>
<span style="color: #666666; font-style: italic;"># for you must do so exclusively on your behalf, under your direction</span>
<span style="color: #666666; font-style: italic;"># and control, on terms that prohibit them from making any copies of</span>
<span style="color: #666666; font-style: italic;"># your copyrighted material outside their relationship with you.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Conveying under any other circumstances is permitted solely under</span>
<span style="color: #666666; font-style: italic;"># the conditions stated below.  Sublicensing is not allowed; section 10</span>
<span style="color: #666666; font-style: italic;"># makes it unnecessary.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   3. Protecting Users' Legal Rights From Anti-Circumvention Law.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   No covered work shall be deemed part of an effective technological</span>
<span style="color: #666666; font-style: italic;"># measure under any applicable law fulfilling obligations under article</span>
<span style="color: #666666; font-style: italic;"># 11 of the WIPO copyright treaty adopted on 20 December 1996, or</span>
<span style="color: #666666; font-style: italic;"># similar laws prohibiting or restricting circumvention of such</span>
<span style="color: #666666; font-style: italic;"># measures.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   When you convey a covered work, you waive any legal power to forbid</span>
<span style="color: #666666; font-style: italic;"># circumvention of technological measures to the extent such circumvention</span>
<span style="color: #666666; font-style: italic;"># is effected by exercising rights under this License with respect to</span>
<span style="color: #666666; font-style: italic;"># the covered work, and you disclaim any intention to limit operation or</span>
<span style="color: #666666; font-style: italic;"># modification of the work as a means of enforcing, against the work's</span>
<span style="color: #666666; font-style: italic;"># users, your or third parties' legal rights to forbid circumvention of</span>
<span style="color: #666666; font-style: italic;"># technological measures.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   4. Conveying Verbatim Copies.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may convey verbatim copies of the Program's source code as you</span>
<span style="color: #666666; font-style: italic;"># receive it, in any medium, provided that you conspicuously and</span>
<span style="color: #666666; font-style: italic;"># appropriately publish on each copy an appropriate copyright notice;</span>
<span style="color: #666666; font-style: italic;"># keep intact all notices stating that this License and any</span>
<span style="color: #666666; font-style: italic;"># non-permissive terms added in accord with section 7 apply to the code;</span>
<span style="color: #666666; font-style: italic;"># keep intact all notices of the absence of any warranty; and give all</span>
<span style="color: #666666; font-style: italic;"># recipients a copy of this License along with the Program.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may charge any price or no price for each copy that you convey,</span>
<span style="color: #666666; font-style: italic;"># and you may offer support or warranty protection for a fee.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   5. Conveying Modified Source Versions.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may convey a work based on the Program, or the modifications to</span>
<span style="color: #666666; font-style: italic;"># produce it from the Program, in the form of source code under the</span>
<span style="color: #666666; font-style: italic;"># terms of section 4, provided that you also meet all of these conditions:</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     a) The work must carry prominent notices stating that you modified</span>
<span style="color: #666666; font-style: italic;">#     it, and giving a relevant date.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     b) The work must carry prominent notices stating that it is</span>
<span style="color: #666666; font-style: italic;">#     released under this License and any conditions added under section</span>
<span style="color: #666666; font-style: italic;">#     7.  This requirement modifies the requirement in section 4 to</span>
<span style="color: #666666; font-style: italic;">#     &quot;keep intact all notices&quot;.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     c) You must license the entire work, as a whole, under this</span>
<span style="color: #666666; font-style: italic;">#     License to anyone who comes into possession of a copy.  This</span>
<span style="color: #666666; font-style: italic;">#     License will therefore apply, along with any applicable section 7</span>
<span style="color: #666666; font-style: italic;">#     additional terms, to the whole of the work, and all its parts,</span>
<span style="color: #666666; font-style: italic;">#     regardless of how they are packaged.  This License gives no</span>
<span style="color: #666666; font-style: italic;">#     permission to license the work in any other way, but it does not</span>
<span style="color: #666666; font-style: italic;">#     invalidate such permission if you have separately received it.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     d) If the work has interactive user interfaces, each must display</span>
<span style="color: #666666; font-style: italic;">#     Appropriate Legal Notices; however, if the Program has interactive</span>
<span style="color: #666666; font-style: italic;">#     interfaces that do not display Appropriate Legal Notices, your</span>
<span style="color: #666666; font-style: italic;">#     work need not make them do so.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A compilation of a covered work with other separate and independent</span>
<span style="color: #666666; font-style: italic;"># works, which are not by their nature extensions of the covered work,</span>
<span style="color: #666666; font-style: italic;"># and which are not combined with it such as to form a larger program,</span>
<span style="color: #666666; font-style: italic;"># in or on a volume of a storage or distribution medium, is called an</span>
<span style="color: #666666; font-style: italic;"># &quot;aggregate&quot; if the compilation and its resulting copyright are not</span>
<span style="color: #666666; font-style: italic;"># used to limit the access or legal rights of the compilation's users</span>
<span style="color: #666666; font-style: italic;"># beyond what the individual works permit.  Inclusion of a covered work</span>
<span style="color: #666666; font-style: italic;"># in an aggregate does not cause this License to apply to the other</span>
<span style="color: #666666; font-style: italic;"># parts of the aggregate.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   6. Conveying Non-Source Forms.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may convey a covered work in object code form under the terms</span>
<span style="color: #666666; font-style: italic;"># of sections 4 and 5, provided that you also convey the</span>
<span style="color: #666666; font-style: italic;"># machine-readable Corresponding Source under the terms of this License,</span>
<span style="color: #666666; font-style: italic;"># in one of these ways:</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     a) Convey the object code in, or embodied in, a physical product</span>
<span style="color: #666666; font-style: italic;">#     (including a physical distribution medium), accompanied by the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source fixed on a durable physical medium</span>
<span style="color: #666666; font-style: italic;">#     customarily used for software interchange.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     b) Convey the object code in, or embodied in, a physical product</span>
<span style="color: #666666; font-style: italic;">#     (including a physical distribution medium), accompanied by a</span>
<span style="color: #666666; font-style: italic;">#     written offer, valid for at least three years and valid for as</span>
<span style="color: #666666; font-style: italic;">#     long as you offer spare parts or customer support for that product</span>
<span style="color: #666666; font-style: italic;">#     model, to give anyone who possesses the object code either (1) a</span>
<span style="color: #666666; font-style: italic;">#     copy of the Corresponding Source for all the software in the</span>
<span style="color: #666666; font-style: italic;">#     product that is covered by this License, on a durable physical</span>
<span style="color: #666666; font-style: italic;">#     medium customarily used for software interchange, for a price no</span>
<span style="color: #666666; font-style: italic;">#     more than your reasonable cost of physically performing this</span>
<span style="color: #666666; font-style: italic;">#     conveying of source, or (2) access to copy the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source from a network server at no charge.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     c) Convey individual copies of the object code with a copy of the</span>
<span style="color: #666666; font-style: italic;">#     written offer to provide the Corresponding Source.  This</span>
<span style="color: #666666; font-style: italic;">#     alternative is allowed only occasionally and noncommercially, and</span>
<span style="color: #666666; font-style: italic;">#     only if you received the object code with such an offer, in accord</span>
<span style="color: #666666; font-style: italic;">#     with subsection 6b.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     d) Convey the object code by offering access from a designated</span>
<span style="color: #666666; font-style: italic;">#     place (gratis or for a charge), and offer equivalent access to the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source in the same way through the same place at no</span>
<span style="color: #666666; font-style: italic;">#     further charge.  You need not require recipients to copy the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source along with the object code.  If the place to</span>
<span style="color: #666666; font-style: italic;">#     copy the object code is a network server, the Corresponding Source</span>
<span style="color: #666666; font-style: italic;">#     may be on a different server (operated by you or a third party)</span>
<span style="color: #666666; font-style: italic;">#     that supports equivalent copying facilities, provided you maintain</span>
<span style="color: #666666; font-style: italic;">#     clear directions next to the object code saying where to find the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source.  Regardless of what server hosts the</span>
<span style="color: #666666; font-style: italic;">#     Corresponding Source, you remain obligated to ensure that it is</span>
<span style="color: #666666; font-style: italic;">#     available for as long as needed to satisfy these requirements.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     e) Convey the object code using peer-to-peer transmission, provided</span>
<span style="color: #666666; font-style: italic;">#     you inform other peers where the object code and Corresponding</span>
<span style="color: #666666; font-style: italic;">#     Source of the work are being offered to the general public at no</span>
<span style="color: #666666; font-style: italic;">#     charge under subsection 6d.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A separable portion of the object code, whose source code is excluded</span>
<span style="color: #666666; font-style: italic;"># from the Corresponding Source as a System Library, need not be</span>
<span style="color: #666666; font-style: italic;"># included in conveying the object code work.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A &quot;User Product&quot; is either (1) a &quot;consumer product&quot;, which means any</span>
<span style="color: #666666; font-style: italic;"># tangible personal property which is normally used for personal, family,</span>
<span style="color: #666666; font-style: italic;"># or household purposes, or (2) anything designed or sold for incorporation</span>
<span style="color: #666666; font-style: italic;"># into a dwelling.  In determining whether a product is a consumer product,</span>
<span style="color: #666666; font-style: italic;"># doubtful cases shall be resolved in favor of coverage.  For a particular</span>
<span style="color: #666666; font-style: italic;"># product received by a particular user, &quot;normally used&quot; refers to a</span>
<span style="color: #666666; font-style: italic;"># typical or common use of that class of product, regardless of the status</span>
<span style="color: #666666; font-style: italic;"># of the particular user or of the way in which the particular user</span>
<span style="color: #666666; font-style: italic;"># actually uses, or expects or is expected to use, the product.  A product</span>
<span style="color: #666666; font-style: italic;"># is a consumer product regardless of whether the product has substantial</span>
<span style="color: #666666; font-style: italic;"># commercial, industrial or non-consumer uses, unless such uses represent</span>
<span style="color: #666666; font-style: italic;"># the only significant mode of use of the product.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   &quot;Installation Information&quot; for a User Product means any methods,</span>
<span style="color: #666666; font-style: italic;"># procedures, authorization keys, or other information required to install</span>
<span style="color: #666666; font-style: italic;"># and execute modified versions of a covered work in that User Product from</span>
<span style="color: #666666; font-style: italic;"># a modified version of its Corresponding Source.  The information must</span>
<span style="color: #666666; font-style: italic;"># suffice to ensure that the continued functioning of the modified object</span>
<span style="color: #666666; font-style: italic;"># code is in no case prevented or interfered with solely because</span>
<span style="color: #666666; font-style: italic;"># modification has been made.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If you convey an object code work under this section in, or with, or</span>
<span style="color: #666666; font-style: italic;"># specifically for use in, a User Product, and the conveying occurs as</span>
<span style="color: #666666; font-style: italic;"># part of a transaction in which the right of possession and use of the</span>
<span style="color: #666666; font-style: italic;"># User Product is transferred to the recipient in perpetuity or for a</span>
<span style="color: #666666; font-style: italic;"># fixed term (regardless of how the transaction is characterized), the</span>
<span style="color: #666666; font-style: italic;"># Corresponding Source conveyed under this section must be accompanied</span>
<span style="color: #666666; font-style: italic;"># by the Installation Information.  But this requirement does not apply</span>
<span style="color: #666666; font-style: italic;"># if neither you nor any third party retains the ability to install</span>
<span style="color: #666666; font-style: italic;"># modified object code on the User Product (for example, the work has</span>
<span style="color: #666666; font-style: italic;"># been installed in ROM).</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The requirement to provide Installation Information does not include a</span>
<span style="color: #666666; font-style: italic;"># requirement to continue to provide support service, warranty, or updates</span>
<span style="color: #666666; font-style: italic;"># for a work that has been modified or installed by the recipient, or for</span>
<span style="color: #666666; font-style: italic;"># the User Product in which it has been modified or installed.  Access to a</span>
<span style="color: #666666; font-style: italic;"># network may be denied when the modification itself materially and</span>
<span style="color: #666666; font-style: italic;"># adversely affects the operation of the network or violates the rules and</span>
<span style="color: #666666; font-style: italic;"># protocols for communication across the network.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Corresponding Source conveyed, and Installation Information provided,</span>
<span style="color: #666666; font-style: italic;"># in accord with this section must be in a format that is publicly</span>
<span style="color: #666666; font-style: italic;"># documented (and with an implementation available to the public in</span>
<span style="color: #666666; font-style: italic;"># source code form), and must require no special password or key for</span>
<span style="color: #666666; font-style: italic;"># unpacking, reading or copying.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   7. Additional Terms.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   &quot;Additional permissions&quot; are terms that supplement the terms of this</span>
<span style="color: #666666; font-style: italic;"># License by making exceptions from one or more of its conditions.</span>
<span style="color: #666666; font-style: italic;"># Additional permissions that are applicable to the entire Program shall</span>
<span style="color: #666666; font-style: italic;"># be treated as though they were included in this License, to the extent</span>
<span style="color: #666666; font-style: italic;"># that they are valid under applicable law.  If additional permissions</span>
<span style="color: #666666; font-style: italic;"># apply only to part of the Program, that part may be used separately</span>
<span style="color: #666666; font-style: italic;"># under those permissions, but the entire Program remains governed by</span>
<span style="color: #666666; font-style: italic;"># this License without regard to the additional permissions.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   When you convey a copy of a covered work, you may at your option</span>
<span style="color: #666666; font-style: italic;"># remove any additional permissions from that copy, or from any part of</span>
<span style="color: #666666; font-style: italic;"># it.  (Additional permissions may be written to require their own</span>
<span style="color: #666666; font-style: italic;"># removal in certain cases when you modify the work.)  You may place</span>
<span style="color: #666666; font-style: italic;"># additional permissions on material, added by you to a covered work,</span>
<span style="color: #666666; font-style: italic;"># for which you have or can give appropriate copyright permission.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Notwithstanding any other provision of this License, for material you</span>
<span style="color: #666666; font-style: italic;"># add to a covered work, you may (if authorized by the copyright holders of</span>
<span style="color: #666666; font-style: italic;"># that material) supplement the terms of this License with terms:</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     a) Disclaiming warranty or limiting liability differently from the</span>
<span style="color: #666666; font-style: italic;">#     terms of sections 15 and 16 of this License; or</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     b) Requiring preservation of specified reasonable legal notices or</span>
<span style="color: #666666; font-style: italic;">#     author attributions in that material or in the Appropriate Legal</span>
<span style="color: #666666; font-style: italic;">#     Notices displayed by works containing it; or</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     c) Prohibiting misrepresentation of the origin of that material, or</span>
<span style="color: #666666; font-style: italic;">#     requiring that modified versions of such material be marked in</span>
<span style="color: #666666; font-style: italic;">#     reasonable ways as different from the original version; or</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     d) Limiting the use for publicity purposes of names of licensors or</span>
<span style="color: #666666; font-style: italic;">#     authors of the material; or</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     e) Declining to grant rights under trademark law for use of some</span>
<span style="color: #666666; font-style: italic;">#     trade names, trademarks, or service marks; or</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#     f) Requiring indemnification of licensors and authors of that</span>
<span style="color: #666666; font-style: italic;">#     material by anyone who conveys the material (or modified versions of</span>
<span style="color: #666666; font-style: italic;">#     it) with contractual assumptions of liability to the recipient, for</span>
<span style="color: #666666; font-style: italic;">#     any liability that these contractual assumptions directly impose on</span>
<span style="color: #666666; font-style: italic;">#     those licensors and authors.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   All other non-permissive additional terms are considered &quot;further</span>
<span style="color: #666666; font-style: italic;"># restrictions&quot; within the meaning of section 10.  If the Program as you</span>
<span style="color: #666666; font-style: italic;"># received it, or any part of it, contains a notice stating that it is</span>
<span style="color: #666666; font-style: italic;"># governed by this License along with a term that is a further</span>
<span style="color: #666666; font-style: italic;"># restriction, you may remove that term.  If a license document contains</span>
<span style="color: #666666; font-style: italic;"># a further restriction but permits relicensing or conveying under this</span>
<span style="color: #666666; font-style: italic;"># License, you may add to a covered work material governed by the terms</span>
<span style="color: #666666; font-style: italic;"># of that license document, provided that the further restriction does</span>
<span style="color: #666666; font-style: italic;"># not survive such relicensing or conveying.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If you add terms to a covered work in accord with this section, you</span>
<span style="color: #666666; font-style: italic;"># must place, in the relevant source files, a statement of the</span>
<span style="color: #666666; font-style: italic;"># additional terms that apply to those files, or a notice indicating</span>
<span style="color: #666666; font-style: italic;"># where to find the applicable terms.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Additional terms, permissive or non-permissive, may be stated in the</span>
<span style="color: #666666; font-style: italic;"># form of a separately written license, or stated as exceptions;</span>
<span style="color: #666666; font-style: italic;"># the above requirements apply either way.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   8. Termination.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may not propagate or modify a covered work except as expressly</span>
<span style="color: #666666; font-style: italic;"># provided under this License.  Any attempt otherwise to propagate or</span>
<span style="color: #666666; font-style: italic;"># modify it is void, and will automatically terminate your rights under</span>
<span style="color: #666666; font-style: italic;"># this License (including any patent licenses granted under the third</span>
<span style="color: #666666; font-style: italic;"># paragraph of section 11).</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   However, if you cease all violation of this License, then your</span>
<span style="color: #666666; font-style: italic;"># license from a particular copyright holder is reinstated (a)</span>
<span style="color: #666666; font-style: italic;"># provisionally, unless and until the copyright holder explicitly and</span>
<span style="color: #666666; font-style: italic;"># finally terminates your license, and (b) permanently, if the copyright</span>
<span style="color: #666666; font-style: italic;"># holder fails to notify you of the violation by some reasonable means</span>
<span style="color: #666666; font-style: italic;"># prior to 60 days after the cessation.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Moreover, your license from a particular copyright holder is</span>
<span style="color: #666666; font-style: italic;"># reinstated permanently if the copyright holder notifies you of the</span>
<span style="color: #666666; font-style: italic;"># violation by some reasonable means, this is the first time you have</span>
<span style="color: #666666; font-style: italic;"># received notice of violation of this License (for any work) from that</span>
<span style="color: #666666; font-style: italic;"># copyright holder, and you cure the violation prior to 30 days after</span>
<span style="color: #666666; font-style: italic;"># your receipt of the notice.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Termination of your rights under this section does not terminate the</span>
<span style="color: #666666; font-style: italic;"># licenses of parties who have received copies or rights from you under</span>
<span style="color: #666666; font-style: italic;"># this License.  If your rights have been terminated and not permanently</span>
<span style="color: #666666; font-style: italic;"># reinstated, you do not qualify to receive new licenses for the same</span>
<span style="color: #666666; font-style: italic;"># material under section 10.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   9. Acceptance Not Required for Having Copies.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You are not required to accept this License in order to receive or</span>
<span style="color: #666666; font-style: italic;"># run a copy of the Program.  Ancillary propagation of a covered work</span>
<span style="color: #666666; font-style: italic;"># occurring solely as a consequence of using peer-to-peer transmission</span>
<span style="color: #666666; font-style: italic;"># to receive a copy likewise does not require acceptance.  However,</span>
<span style="color: #666666; font-style: italic;"># nothing other than this License grants you permission to propagate or</span>
<span style="color: #666666; font-style: italic;"># modify any covered work.  These actions infringe copyright if you do</span>
<span style="color: #666666; font-style: italic;"># not accept this License.  Therefore, by modifying or propagating a</span>
<span style="color: #666666; font-style: italic;"># covered work, you indicate your acceptance of this License to do so.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   10. Automatic Licensing of Downstream Recipients.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Each time you convey a covered work, the recipient automatically</span>
<span style="color: #666666; font-style: italic;"># receives a license from the original licensors, to run, modify and</span>
<span style="color: #666666; font-style: italic;"># propagate that work, subject to this License.  You are not responsible</span>
<span style="color: #666666; font-style: italic;"># for enforcing compliance by third parties with this License.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   An &quot;entity transaction&quot; is a transaction transferring control of an</span>
<span style="color: #666666; font-style: italic;"># organization, or substantially all assets of one, or subdividing an</span>
<span style="color: #666666; font-style: italic;"># organization, or merging organizations.  If propagation of a covered</span>
<span style="color: #666666; font-style: italic;"># work results from an entity transaction, each party to that</span>
<span style="color: #666666; font-style: italic;"># transaction who receives a copy of the work also receives whatever</span>
<span style="color: #666666; font-style: italic;"># licenses to the work the party's predecessor in interest had or could</span>
<span style="color: #666666; font-style: italic;"># give under the previous paragraph, plus a right to possession of the</span>
<span style="color: #666666; font-style: italic;"># Corresponding Source of the work from the predecessor in interest, if</span>
<span style="color: #666666; font-style: italic;"># the predecessor has it or can get it with reasonable efforts.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   You may not impose any further restrictions on the exercise of the</span>
<span style="color: #666666; font-style: italic;"># rights granted or affirmed under this License.  For example, you may</span>
<span style="color: #666666; font-style: italic;"># not impose a license fee, royalty, or other charge for exercise of</span>
<span style="color: #666666; font-style: italic;"># rights granted under this License, and you may not initiate litigation</span>
<span style="color: #666666; font-style: italic;"># (including a cross-claim or counterclaim in a lawsuit) alleging that</span>
<span style="color: #666666; font-style: italic;"># any patent claim is infringed by making, using, selling, offering for</span>
<span style="color: #666666; font-style: italic;"># sale, or importing the Program or any portion of it.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   11. Patents.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A &quot;contributor&quot; is a copyright holder who authorizes use under this</span>
<span style="color: #666666; font-style: italic;"># License of the Program or a work on which the Program is based.  The</span>
<span style="color: #666666; font-style: italic;"># work thus licensed is called the contributor's &quot;contributor version&quot;.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A contributor's &quot;essential patent claims&quot; are all patent claims</span>
<span style="color: #666666; font-style: italic;"># owned or controlled by the contributor, whether already acquired or</span>
<span style="color: #666666; font-style: italic;"># hereafter acquired, that would be infringed by some manner, permitted</span>
<span style="color: #666666; font-style: italic;"># by this License, of making, using, or selling its contributor version,</span>
<span style="color: #666666; font-style: italic;"># but do not include claims that would be infringed only as a</span>
<span style="color: #666666; font-style: italic;"># consequence of further modification of the contributor version.  For</span>
<span style="color: #666666; font-style: italic;"># purposes of this definition, &quot;control&quot; includes the right to grant</span>
<span style="color: #666666; font-style: italic;"># patent sublicenses in a manner consistent with the requirements of</span>
<span style="color: #666666; font-style: italic;"># this License.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Each contributor grants you a non-exclusive, worldwide, royalty-free</span>
<span style="color: #666666; font-style: italic;"># patent license under the contributor's essential patent claims, to</span>
<span style="color: #666666; font-style: italic;"># make, use, sell, offer for sale, import and otherwise run, modify and</span>
<span style="color: #666666; font-style: italic;"># propagate the contents of its contributor version.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   In the following three paragraphs, a &quot;patent license&quot; is any express</span>
<span style="color: #666666; font-style: italic;"># agreement or commitment, however denominated, not to enforce a patent</span>
<span style="color: #666666; font-style: italic;"># (such as an express permission to practice a patent or covenant not to</span>
<span style="color: #666666; font-style: italic;"># sue for patent infringement).  To &quot;grant&quot; such a patent license to a</span>
<span style="color: #666666; font-style: italic;"># party means to make such an agreement or commitment not to enforce a</span>
<span style="color: #666666; font-style: italic;"># patent against the party.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If you convey a covered work, knowingly relying on a patent license,</span>
<span style="color: #666666; font-style: italic;"># and the Corresponding Source of the work is not available for anyone</span>
<span style="color: #666666; font-style: italic;"># to copy, free of charge and under the terms of this License, through a</span>
<span style="color: #666666; font-style: italic;"># publicly available network server or other readily accessible means,</span>
<span style="color: #666666; font-style: italic;"># then you must either (1) cause the Corresponding Source to be so</span>
<span style="color: #666666; font-style: italic;"># available, or (2) arrange to deprive yourself of the benefit of the</span>
<span style="color: #666666; font-style: italic;"># patent license for this particular work, or (3) arrange, in a manner</span>
<span style="color: #666666; font-style: italic;"># consistent with the requirements of this License, to extend the patent</span>
<span style="color: #666666; font-style: italic;"># license to downstream recipients.  &quot;Knowingly relying&quot; means you have</span>
<span style="color: #666666; font-style: italic;"># actual knowledge that, but for the patent license, your conveying the</span>
<span style="color: #666666; font-style: italic;"># covered work in a country, or your recipient's use of the covered work</span>
<span style="color: #666666; font-style: italic;"># in a country, would infringe one or more identifiable patents in that</span>
<span style="color: #666666; font-style: italic;"># country that you have reason to believe are valid.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If, pursuant to or in connection with a single transaction or</span>
<span style="color: #666666; font-style: italic;"># arrangement, you convey, or propagate by procuring conveyance of, a</span>
<span style="color: #666666; font-style: italic;"># covered work, and grant a patent license to some of the parties</span>
<span style="color: #666666; font-style: italic;"># receiving the covered work authorizing them to use, propagate, modify</span>
<span style="color: #666666; font-style: italic;"># or convey a specific copy of the covered work, then the patent license</span>
<span style="color: #666666; font-style: italic;"># you grant is automatically extended to all recipients of the covered</span>
<span style="color: #666666; font-style: italic;"># work and works based on it.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   A patent license is &quot;discriminatory&quot; if it does not include within</span>
<span style="color: #666666; font-style: italic;"># the scope of its coverage, prohibits the exercise of, or is</span>
<span style="color: #666666; font-style: italic;"># conditioned on the non-exercise of one or more of the rights that are</span>
<span style="color: #666666; font-style: italic;"># specifically granted under this License.  You may not convey a covered</span>
<span style="color: #666666; font-style: italic;"># work if you are a party to an arrangement with a third party that is</span>
<span style="color: #666666; font-style: italic;"># in the business of distributing software, under which you make payment</span>
<span style="color: #666666; font-style: italic;"># to the third party based on the extent of your activity of conveying</span>
<span style="color: #666666; font-style: italic;"># the work, and under which the third party grants, to any of the</span>
<span style="color: #666666; font-style: italic;"># parties who would receive the covered work from you, a discriminatory</span>
<span style="color: #666666; font-style: italic;"># patent license (a) in connection with copies of the covered work</span>
<span style="color: #666666; font-style: italic;"># conveyed by you (or copies made from those copies), or (b) primarily</span>
<span style="color: #666666; font-style: italic;"># for and in connection with specific products or compilations that</span>
<span style="color: #666666; font-style: italic;"># contain the covered work, unless you entered into that arrangement,</span>
<span style="color: #666666; font-style: italic;"># or that patent license was granted, prior to 28 March 2007.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Nothing in this License shall be construed as excluding or limiting</span>
<span style="color: #666666; font-style: italic;"># any implied license or other defenses to infringement that may</span>
<span style="color: #666666; font-style: italic;"># otherwise be available to you under applicable patent law.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   12. No Surrender of Others' Freedom.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If conditions are imposed on you (whether by court order, agreement or</span>
<span style="color: #666666; font-style: italic;"># otherwise) that contradict the conditions of this License, they do not</span>
<span style="color: #666666; font-style: italic;"># excuse you from the conditions of this License.  If you cannot convey a</span>
<span style="color: #666666; font-style: italic;"># covered work so as to satisfy simultaneously your obligations under this</span>
<span style="color: #666666; font-style: italic;"># License and any other pertinent obligations, then as a consequence you may</span>
<span style="color: #666666; font-style: italic;"># not convey it at all.  For example, if you agree to terms that obligate you</span>
<span style="color: #666666; font-style: italic;"># to collect a royalty for further conveying from those to whom you convey</span>
<span style="color: #666666; font-style: italic;"># the Program, the only way you could satisfy both those terms and this</span>
<span style="color: #666666; font-style: italic;"># License would be to refrain entirely from conveying the Program.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   13. Use with the GNU Affero General Public License.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Notwithstanding any other provision of this License, you have</span>
<span style="color: #666666; font-style: italic;"># permission to link or combine any covered work with a work licensed</span>
<span style="color: #666666; font-style: italic;"># under version 3 of the GNU Affero General Public License into a single</span>
<span style="color: #666666; font-style: italic;"># combined work, and to convey the resulting work.  The terms of this</span>
<span style="color: #666666; font-style: italic;"># License will continue to apply to the part which is the covered work,</span>
<span style="color: #666666; font-style: italic;"># but the special requirements of the GNU Affero General Public License,</span>
<span style="color: #666666; font-style: italic;"># section 13, concerning interaction through a network will apply to the</span>
<span style="color: #666666; font-style: italic;"># combination as such.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   14. Revised Versions of this License.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   The Free Software Foundation may publish revised and/or new versions of</span>
<span style="color: #666666; font-style: italic;"># the GNU General Public License from time to time.  Such new versions will</span>
<span style="color: #666666; font-style: italic;"># be similar in spirit to the present version, but may differ in detail to</span>
<span style="color: #666666; font-style: italic;"># address new problems or concerns.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Each version is given a distinguishing version number.  If the</span>
<span style="color: #666666; font-style: italic;"># Program specifies that a certain numbered version of the GNU General</span>
<span style="color: #666666; font-style: italic;"># Public License &quot;or any later version&quot; applies to it, you have the</span>
<span style="color: #666666; font-style: italic;"># option of following the terms and conditions either of that numbered</span>
<span style="color: #666666; font-style: italic;"># version or of any later version published by the Free Software</span>
<span style="color: #666666; font-style: italic;"># Foundation.  If the Program does not specify a version number of the</span>
<span style="color: #666666; font-style: italic;"># GNU General Public License, you may choose any version ever published</span>
<span style="color: #666666; font-style: italic;"># by the Free Software Foundation.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If the Program specifies that a proxy can decide which future</span>
<span style="color: #666666; font-style: italic;"># versions of the GNU General Public License can be used, that proxy's</span>
<span style="color: #666666; font-style: italic;"># public statement of acceptance of a version permanently authorizes you</span>
<span style="color: #666666; font-style: italic;"># to choose that version for the Program.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   Later license versions may give you additional or different</span>
<span style="color: #666666; font-style: italic;"># permissions.  However, no additional obligations are imposed on any</span>
<span style="color: #666666; font-style: italic;"># author or copyright holder as a result of your choosing to follow a</span>
<span style="color: #666666; font-style: italic;"># later version.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   15. Disclaimer of Warranty.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY</span>
<span style="color: #666666; font-style: italic;"># APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT</span>
<span style="color: #666666; font-style: italic;"># HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM &quot;AS IS&quot; WITHOUT WARRANTY</span>
<span style="color: #666666; font-style: italic;"># OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,</span>
<span style="color: #666666; font-style: italic;"># THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
<span style="color: #666666; font-style: italic;"># PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM</span>
<span style="color: #666666; font-style: italic;"># IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF</span>
<span style="color: #666666; font-style: italic;"># ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   16. Limitation of Liability.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING</span>
<span style="color: #666666; font-style: italic;"># WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS</span>
<span style="color: #666666; font-style: italic;"># THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY</span>
<span style="color: #666666; font-style: italic;"># GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE</span>
<span style="color: #666666; font-style: italic;"># USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF</span>
<span style="color: #666666; font-style: italic;"># DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD</span>
<span style="color: #666666; font-style: italic;"># PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),</span>
<span style="color: #666666; font-style: italic;"># EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF</span>
<span style="color: #666666; font-style: italic;"># SUCH DAMAGES.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   17. Interpretation of Sections 15 and 16.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   If the disclaimer of warranty and limitation of liability provided</span>
<span style="color: #666666; font-style: italic;"># above cannot be given local legal effect according to their terms,</span>
<span style="color: #666666; font-style: italic;"># reviewing courts shall apply local law that most closely approximates</span>
<span style="color: #666666; font-style: italic;"># an absolute waiver of all civil liability in connection with the</span>
<span style="color: #666666; font-style: italic;"># Program, unless a warranty or assumption of liability accompanies a</span>
<span style="color: #666666; font-style: italic;"># copy of the Program in return for a fee.</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#                      END OF TERMS AND CONDITIONS</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>xsl:stylesheet <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> xmlns:<span style="color: #007800;">xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>xsl:output <span style="color: #007800;">method</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>xsl:template <span style="color: #007800;">match</span>=<span style="color: #ff0000;">&quot;sheetData&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:apply-templates <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;row&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>xsl:template <span style="color: #007800;">match</span>=<span style="color: #ff0000;">&quot;row&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:for-each <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;'INSERT INTO cell_data (cell,style,type,value) VALUES (|'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;@r&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;!</span>-- cell identifier --<span style="color: #000000; font-weight: bold;">&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;'|,|'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;@s&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;!</span>-- format --<span style="color: #000000; font-weight: bold;">&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;'|,|'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;@t&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;!</span>-- data <span style="color: #7a0874; font-weight: bold;">type</span> --<span style="color: #000000; font-weight: bold;">&gt;</span> 
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;'|,|'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;v&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;!</span>-- the calculated value --<span style="color: #000000; font-weight: bold;">&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;'|);'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">test</span>=<span style="color: #ff0000;">&quot;position() != last()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;!</span>-- <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:value-of <span style="color: #007800;">select</span>=<span style="color: #ff0000;">&quot;');'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> --<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:text<span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #666666; font-style: italic;">#10;&lt;/xsl:text&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;/</span>xsl:<span style="color: #000000; font-weight: bold;">if</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;/</span>xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>xsl:text<span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #666666; font-style: italic;">#10;&lt;/xsl:text&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/12/xlsx2csv/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Writing to syslog in a bash script</title>
		<link>http://kirk.webfinish.com/2009/11/writing-to-syslog-in-a-bash-script/</link>
		<comments>http://kirk.webfinish.com/2009/11/writing-to-syslog-in-a-bash-script/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 21:52:42 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=85</guid>
		<description><![CDATA[Here's a little snippet to show how to use logger (included with OS/X, don't know on other platforms) to syslog errors from a bash script.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little snippet to show how to use logger (included with OS/X, don&#8217;t know on other platforms) to syslog errors from a bash script.  This is probably most useful for a daemonized process, but would work in any script.</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="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">function</span> debug_log <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>
logger <span style="color: #660033;">-t</span> <span style="color: #007800;">$0</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$USER</span> : <span style="color: #007800;">$BASH_COMMAND</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">trap</span> debug_log DEBUG
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This is a trap&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This is another trap&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/11/writing-to-syslog-in-a-bash-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple bash password generator</title>
		<link>http://kirk.webfinish.com/2009/11/simple-bash-password-generator/</link>
		<comments>http://kirk.webfinish.com/2009/11/simple-bash-password-generator/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 20:00:52 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=81</guid>
		<description><![CDATA[Quick arbitrary length password generator.]]></description>
			<content:encoded><![CDATA[<p>This is just a quick way to create arbitrary passwords that may contain letters, numbers, and symbols.  It takes an optional length parameter.</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
</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;">#</span>
<span style="color: #666666; font-style: italic;">#          FILE:  password</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./password [ length ]</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  Generate a secure password using /dev/urandom</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#       OPTIONS:  ---</span>
<span style="color: #666666; font-style: italic;">#  REQUIREMENTS:  ---</span>
<span style="color: #666666; font-style: italic;">#          BUGS:  ---</span>
<span style="color: #666666; font-style: italic;">#         NOTES:  ---</span>
<span style="color: #666666; font-style: italic;">#       VERSION:  1.0</span>
<span style="color: #666666; font-style: italic;">#       CREATED:  10/13/2009 11:10:39 CDT</span>
<span style="color: #666666; font-style: italic;">#      REVISION:  ---</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> usage <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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOS
    Usage: `basename $0` [ length ] [ --usage | --help ]
    Default password length is 12
EOS</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span> 
    <span style="color: #ff0000;">'--usage'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      usage
      <span style="color: #7a0874; font-weight: bold;">exit</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #ff0000;">'--help'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     usage
     <span style="color: #7a0874; font-weight: bold;">exit</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">length</span>=<span style="color: #007800;">$1</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$length</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      usage
      <span style="color: #7a0874; font-weight: bold;">exit</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span> 
  <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$length</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">length</span>=<span style="color: #000000;">12</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$length</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">4</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> password is too weak to produce
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$length</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">8</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> password is weak
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">declare</span> password
<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;">&#91;</span> <span style="color: #800000;">${#password}</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$length</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">char</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #007800;">bs</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">count</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> mimencode<span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">char</span>=<span style="color: #800000;">${char:0:1}</span>
  <span style="color: #007800;">password</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$password</span><span style="color: #007800;">$char</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$password</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/11/simple-bash-password-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>launchd script for OS/X for bash daemon</title>
		<link>http://kirk.webfinish.com/2009/11/launchd-script-for-osx-for-bash-daemon/</link>
		<comments>http://kirk.webfinish.com/2009/11/launchd-script-for-osx-for-bash-daemon/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 22:21:49 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=69</guid>
		<description><![CDATA[This is the promised launchd script to run the service in an earlier post.]]></description>
			<content:encoded><![CDATA[<p>This is the promised launchd script to run the service in an earlier post.</p>
<p>The name of this file is /Library/LaunchDaemons/com.{domain_name}.{service_name}.plist</p>
<p>Replace any text in curly braces {} with some appropriate information for your script.</p>
<p>When you are finished creating the file, load it with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
launchctl load <span style="color: #660033;">-w</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>com.<span style="color: #7a0874; font-weight: bold;">&#123;</span>domain_name<span style="color: #7a0874; font-weight: bold;">&#125;</span>.<span style="color: #7a0874; font-weight: bold;">&#123;</span>service_name<span style="color: #7a0874; font-weight: bold;">&#125;</span>.plist</pre></div></div>

<p>It should crank right up and start doing its&#8217; thang.</p>
<p>Here&#8217;s the content of the .plist 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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Enabled<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>GroupName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>staff<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>KeepAlive<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.{domain_name}.{service_name}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Program<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/bin/{script_name}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ProgramArguments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{script_name}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>start<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>--nofork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>QueueDirectories<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ServiceDescription<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Some creative description of your service.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UserName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{user_name}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>WatchPaths<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/11/launchd-script-for-osx-for-bash-daemon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OS/X daemon script template</title>
		<link>http://kirk.webfinish.com/2009/11/osx-daemon-script-template/</link>
		<comments>http://kirk.webfinish.com/2009/11/osx-daemon-script-template/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 22:57:13 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[os/x mac bash daemon script]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2009/11/osx-daemon-script-template/</guid>
		<description><![CDATA[This is a daemon script written for OS/X in bash.  It can be run either as a daemon or a launchd service. ]]></description>
			<content:encoded><![CDATA[<p>This is a daemon script written for OS/X in bash.  It can be run either as a daemon or a launchd service.  The launchd service file will follow in a later post.</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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
</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;"># put these lines in the file header comment</span>
<span style="color: #666666; font-style: italic;">#          FILE:  |FILENAME|</span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./|FILENAME| start [ stop | restart ] [ --nofork ] [ --debug ]</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#Uncomment the following line to echo all commands to the terminal</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#set -x</span>
<span style="color: #666666; font-style: italic;"># better yet, set the --debug command line flag and syslog it.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  cleanup</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  post service processing (clean temp space,pid files)</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  none</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> cleanup <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: #ff0000;">&quot;trap exit&quot;</span>
  <span style="color: #666666; font-style: italic;">#Don't recurse in the exit trap</span>
  <span style="color: #7a0874; font-weight: bold;">trap</span> - INT TERM EXIT
  <span style="color: #666666; font-style: italic;">#remove the pid file cleanly on exit</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
  <span style="color: #666666; font-style: italic;">#add other post processing cleanup here</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  isrunning</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  is any previous instance of this script already running</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  pidfile location</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  boolean</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> isrunning<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: #007800;">pidfile</span>=<span style="color: #ff0000;">&quot;$1&quot;</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: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>  <span style="color: #666666; font-style: italic;">#pid file is nonexistent</span>
  <span style="color: #007800;">procpid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$procpid</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>  <span style="color: #666666; font-style: italic;">#pid file contains no pid</span>
  <span style="color: #666666; font-style: italic;"># check process list for pid existence and is an instance of this script</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: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$procpid</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">value</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">value</span>=<span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$value</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  createpidfile</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  atomic creation of pid file with no race condition</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  the pid to put in the file, the filename to use as a lock</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  none</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> createpidfile<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: #007800;">mypid</span>=<span style="color: #007800;">$1</span>
  <span style="color: #007800;">pidfile</span>=<span style="color: #007800;">$2</span>
  <span style="color: #666666; font-style: italic;">#Close stderr, don't overwrite existing file, shove my pid in the lock file.</span>
  $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span>-; <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-o</span> noclobber; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mypid</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</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: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #666666; font-style: italic;">#Lock file creation failed</span>
  <span style="color: #007800;">procpid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$mypid</span> <span style="color: #660033;">-ne</span> <span style="color: #007800;">$procpid</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#I'm not the pid in the lock file</span>
    <span style="color: #666666; font-style: italic;"># Is the process pid in the lockfile still running?</span>
    isrunning <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      <span style="color: #666666; font-style: italic;"># No.  Kill the pidfile and relaunch ourselves properly.</span>
      <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
      <span style="color: #007800;">$0</span> $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  <span style="color: #666666; font-style: italic;">#  I win!  set a trap for the lockfile on exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#  Check number of command line arguments</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <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: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>Usage:  <span style="color: #007800;">${0##/*/}</span> start [ | stop | restart ] [ --nofork ] [ --debug ]&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: #666666; font-style: italic;">#A launchd script in OSX is not supposed to fork</span>
<span style="color: #007800;">nofork</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$*&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;\-\-nofork&quot;</span><span style="color: #000000; font-weight: bold;">`</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: #660033;">-z</span> <span style="color: #007800;">$nofork</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">nofork</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$nofork</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">nofork</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #666666; font-style: italic;">#check to send everything to syslog</span>
<span style="color: #007800;">debug</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$*&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;\-\-debug&quot;</span><span style="color: #000000; font-weight: bold;">`</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: #660033;">-z</span> <span style="color: #007800;">$debug</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">debug</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$debug</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">debug</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#configuration</span>
<span style="color: #007800;">basename</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`basename $0 .sh`</span>&quot;</span>
<span style="color: #666666; font-style: italic;"># look for the conf file in the same folder as the script</span>
<span style="color: #007800;">conf</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(dirname $(which $0)</span>)/<span style="color: #007800;">${basename}</span>.conf&quot;</span> <span style="color: #666666; font-style: italic;">#&lt;-- which handles &quot;bash -x $0 start&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$conf</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$conf</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  pidfilename</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  create a predictable pid file name, put it in the right inode</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  path and filename</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> pidfilename<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: #007800;">myfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;$0&quot;</span> .sh<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #007800;">whoiam</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #007800;">mypidfile</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$myfile</span>.pid
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$whoiam</span>&quot;</span> == <span style="color: #ff0000;">'root'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">mypidfile</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><span style="color: #007800;">$myfile</span>.pid
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$mypidfile</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">pidfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>pidfilename<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#find the temp directory </span>
<span style="color: #007800;">tempfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">mktemp</span> <span style="color: #660033;">-t</span> j<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
<span style="color: #666666; font-style: italic;">#put all of your incidentals in the tempdir </span>
<span style="color: #007800;">tempdir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$tempfile</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$tempfile</span> 
<span style="color: #666666; font-style: italic;">#Do all further processing from the root </span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span> 
<span style="color: #666666; font-style: italic;"># Load the daemon template for OSX </span>
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.common 
<span style="color: #666666; font-style: italic;">#traps trap 'source $conf' 1  </span>
<span style="color: #666666; font-style: italic;"># response to kill -s HUP $$ should be to read the config file. </span>
<span style="color: #666666; font-style: italic;">#trap 'echo trap  0; rm -f &quot;$pidfile&quot;; exit'  0     #can't trap this, daemon will exit when parent dies. </span>
<span style="color: #666666; font-style: italic;">#trap 'cleanup'  3 15     #clean up the pidfile </span>
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================ </span>
<span style="color: #666666; font-style: italic;">#          NAME:  main </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  Allows daemon to be run in background </span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none </span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  void </span>
<span style="color: #666666; font-style: italic;">#=============================================================================== </span>
<span style="color: #000000; font-weight: bold;">function</span> main<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: #666666; font-style: italic;">#         Put your service code here </span>
<span style="color: #000000; font-weight: bold;">while</span> : <span style="color: #666666; font-style: italic;"># Loop forever </span>
<span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$RANDOM</span>
<span style="color: #000000; font-weight: bold;">done</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================ </span>
<span style="color: #666666; font-style: italic;">#          NAME:  StartService </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  implements function from /etc/rc.common </span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none </span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  void </span>
<span style="color: #666666; font-style: italic;">#=============================================================================== </span>
StartService <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>   
&nbsp;
  CheckForNetwork   
&nbsp;
  isrunning <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
         <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$basename</span> is already running&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: #666666; font-style: italic;"># do the service</span>
   <span style="color: #666666; font-style: italic;">#   no fork method for launchd service   </span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$nofork</span>&quot;</span> == <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
       <span style="color: #666666; font-style: italic;">#pid file with this process id</span>
      createpidfile <span style="color: #007800;">$$</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
      <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'cleanup'</span> INT TERM EXIT
      <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$debug</span>&quot;</span> == <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'logger -t $0 -i -- $USER : $BASH_COMMAND'</span> DEBUG <span style="color: #666666; font-style: italic;">#syslog everything if we're debugging </span>
      <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'logger -t $0 -i -- $USER : $BASH_COMMAND'</span> ERR  <span style="color: #666666; font-style: italic;">#log errors regardless </span>
      <span style="color: #666666; font-style: italic;">#echo $$ &gt; $pidfile</span>
      main
      <span style="color: #7a0874; font-weight: bold;">exit</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$debug</span>&quot;</span> == <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'logger -t $0 -i -- $USER : $BASH_COMMAND'</span> DEBUG <span style="color: #666666; font-style: italic;">#syslog everything if we're debugging </span>
  <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'logger -t $0 -i -- $USER : $BASH_COMMAND'</span> ERR  <span style="color: #666666; font-style: italic;">#log errors regardless </span>
  <span style="color: #666666; font-style: italic;"># fork and exit</span>
  main <span style="color: #000000; font-weight: bold;">&amp;</span>
  <span style="color: #666666; font-style: italic;"># create a pid file with the pid of the child</span>
  <span style="color: #666666; font-style: italic;">#  the parent will go away and leave the child owned by init</span>
  createpidfile <span style="color: #007800;">$!</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'cleanup'</span> INT TERM 
<span style="color: #666666; font-style: italic;"># #echo $! &gt; $pidfile</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  StopService</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  implements the function from /etc/rc.common</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  void</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
StopService <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>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">kill</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  <span style="color: #666666; font-style: italic;">#touch &quot;$quit&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  RestartService</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  implements the function from /etc/rc.common</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  void</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
RestartService <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>
  StopService
  StartService
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#  Call the function declared in /etc/rc.common to daemonize process</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------------------</span>
RunService <span style="color: #ff0000;">&quot;$1&quot;</span>  <span style="color: #666666; font-style: italic;">#First parameter is start/stop/restart</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/11/osx-daemon-script-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash shell script to manage pid file creation/deletion</title>
		<link>http://kirk.webfinish.com/2009/10/bash-shell-script-to-manage-pid-file-creationdeletion/</link>
		<comments>http://kirk.webfinish.com/2009/10/bash-shell-script-to-manage-pid-file-creationdeletion/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 20:52:42 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[bash shell script pid]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=52</guid>
		<description><![CDATA[ You want your script to execute without overlapping another execution.]]></description>
			<content:encoded><![CDATA[<p>Problem: You want your script to execute without overlapping another execution.<br />
Solution: Make a flag file so you know that your script is already executing.<br />
Extended problem: What if your script dies and leaves the flag file behind?<br />
Extended solution: Check the process list to see if the old instance is still alive.<br />
Ext. Ext. Problem: What if somebody kills my script?<br />
Ext. Ext. Solution: Trap the abnormal exit and clean up properly.<br />
Ext. Ext. Ext. Problem:  What if someone else is invoking a script with exactly the same name as mine?<br />
Ext. Ext. Ext. Solution: You&#8217;re screwed.  Give your script a really long descriptive name so this won&#8217;t happen.</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
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  pidfilename</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  create a predictable pid file name, put it in the right inode</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  path and filename</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> pidfilename<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: #007800;">myfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;$0&quot;</span> .sh<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #007800;">whoiam</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #007800;">mypidfile</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$myfile</span>.pid
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$whoiam</span>&quot;</span> == <span style="color: #ff0000;">'root'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">mypidfile</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><span style="color: #007800;">$myfile</span>.pid
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$mypidfile</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  cleanup</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  post service processing (clean temp space,pid files)</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  none</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  none</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> cleanup <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: #666666; font-style: italic;">#Don't recurse in the exit trap</span>
  <span style="color: #7a0874; font-weight: bold;">trap</span> - INT TERM EXIT
  <span style="color: #666666; font-style: italic;">#remove the pid file cleanly on exit</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mypidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mypidfile</span>&quot;</span>
  <span style="color: #666666; font-style: italic;">#add other post processing cleanup here</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  isrunning</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  is any previous instance of this script already running</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  pidfile location</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  boolean 0|1</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> isrunning<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: #007800;">pidfile</span>=<span style="color: #ff0000;">&quot;$1&quot;</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: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>  <span style="color: #666666; font-style: italic;">#pid file is nonexistent</span>
  <span style="color: #007800;">procpid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$procpid</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>  <span style="color: #666666; font-style: italic;">#pid file contains no pid</span>
  <span style="color: #666666; font-style: italic;"># check process list for pid existence and is an instance of this script</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: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$procpid</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">value</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">value</span>=<span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$value</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#          NAME:  createpidfile</span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  atomic creation of pid file with no race condition</span>
<span style="color: #666666; font-style: italic;">#    PARAMETERS:  the pid to put in the file, the filename to use as a lock</span>
<span style="color: #666666; font-style: italic;">#       RETURNS:  none</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> createpidfile<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: #007800;">mypid</span>=<span style="color: #007800;">$1</span>
  <span style="color: #007800;">pidfile</span>=<span style="color: #007800;">$2</span>
  <span style="color: #666666; font-style: italic;">#Close stderr, don't overwrite existing file, shove my pid in the lock file.</span>
  $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span>-; <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-o</span> noclobber; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mypid</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</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: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #666666; font-style: italic;">#Lock file creation failed</span>
  <span style="color: #007800;">procpid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$mypid</span> <span style="color: #660033;">-ne</span> <span style="color: #007800;">$procpid</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#I'm not the pid in the lock file</span>
    <span style="color: #666666; font-style: italic;"># Is the process pid in the lockfile still running?</span>
    isrunning <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      <span style="color: #666666; font-style: italic;"># No.  Kill the pidfile and relaunch ourselves properly.</span>
      <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pidfile</span>&quot;</span>
      <span style="color: #007800;">$0</span> $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">mypidfile</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>pidfilename<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
createpidfile <span style="color: #007800;">$$</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mypidfile</span>&quot;</span>
<span style="color: #666666; font-style: italic;">#  I win!  set a trap for the lockfile on exit</span>
<span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">'cleanup'</span> INT TERM EXIT
<span style="color: #666666; font-style: italic;"># Go ahead and do some processing </span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span></pre></td></tr></table></div>

<p>I have been informed that there are a few corner cases that this script does not cover.  For one, I may have write access to the pidfile, but not delete access.  This would cause the second instance of the script to start a fork bomb.  I can&#8217;t imagine a case where this would actually be true, so I&#8217;m not bothering to fix it.  Second, this script forks itself in the background if the pid file is determined to be abandoned (i.e. power shut off).  This might cause some calling script to return and proceed when the child is not finished.  I&#8217;m not sure how to fix that without making the code extremely ugly, but when I think of something, I&#8217;ll stick it in here.</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/10/bash-shell-script-to-manage-pid-file-creationdeletion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>bash shell script to use getopts with gnu style long positional parameters</title>
		<link>http://kirk.webfinish.com/2009/10/bash-shell-script-to-use-getopts-with-gnu-style-long-positional-parameters/</link>
		<comments>http://kirk.webfinish.com/2009/10/bash-shell-script-to-use-getopts-with-gnu-style-long-positional-parameters/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 00:55:10 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[bash shell getopts positional parameters eval]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2009/10/bash-shell-script-to-use-getopts-with-gnu-style-long-positional-parameters/</guid>
		<description><![CDATA[Problem: You want to support &#8211;really-long-option-names in your bash script and getopts won&#8217;t do it. More problems: You don&#8217;t want to use getopt because you want cross platform support or your platform isn&#8217;t supported. More problems than that: I can&#8217;t help with existential issues. Solution: Rewrite the long options into short options and then use [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: You want to support &#8211;really-long-option-names in your bash script and getopts won&#8217;t do it.<br />
More problems: You don&#8217;t want to use getopt because you want cross platform support or your platform isn&#8217;t supported.<br />
More problems than that: I can&#8217;t help with existential issues.<br />
Solution:  Rewrite the long options into short options and then use getopts.</p>
<p>./args.sh -b -c -a &#8220;yada yada&#8221; &#8211;some-other-gnu &#8211;long-gnu-option</p>
<p>content of args.sh:</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
</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: #000000; font-weight: bold;">for</span> arg
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$arg</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #666666; font-style: italic;">#translate --gnu-long-options to -g (short options)</span>
        --some-other-gnu<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-g &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
       --long-gnu-option<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span>-l &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
       <span style="color: #666666; font-style: italic;">#pass through anything else</span>
       <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${arg:0:1}</span>&quot;</span> == <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">delim</span>=<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
           <span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${args}</span><span style="color: #007800;">${delim}</span><span style="color: #007800;">${arg}</span><span style="color: #007800;">${delim}</span> &quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Reset the positional parameters to the short options</span>
<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$args</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;:a:gl&quot;</span> option <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<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;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$option</span> <span style="color: #000000; font-weight: bold;">in</span>
        g<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;some other gnu option&quot;</span><span style="color: #000000; font-weight: bold;">;;</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;long gnu option&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
        a<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${OPTARG[@]}</span><span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$OPTARG</span> is an unrecognized option<span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Output:</p>
<p>b is an unrecognized option<br />
c is an unrecognized option<br />
yada yada<br />
some other gnu option<br />
long gnu option</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/10/bash-shell-script-to-use-getopts-with-gnu-style-long-positional-parameters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>sed script to trim leading and trailing spaces</title>
		<link>http://kirk.webfinish.com/2009/02/sed-script-to-trim-leading-and-trailing-spaces/</link>
		<comments>http://kirk.webfinish.com/2009/02/sed-script-to-trim-leading-and-trailing-spaces/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 23:07:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=20</guid>
		<description><![CDATA[i couldn&#8217;t find this anywhere, so just to make it generally public, this is my trim function: sed &#8216;s/^[[:space:]]*\(.*\)[[:space:]]*$/\1/&#8217; For who&#8217;s looking, this command says: from beginning of line ^ take any amount of whitespace [[:space:]] then create a group containing anything \(.*\) up to whitespace at the end of the line [[:space:]]*$ replace this [...]]]></description>
			<content:encoded><![CDATA[<p>i couldn&#8217;t find this anywhere, so just to make it generally public, this is my trim function:</p>
<p>sed &#8216;s/^[[:space:]]*\(.*\)[[:space:]]*$/\1/&#8217;</p>
<p>For who&#8217;s looking, this command says:</p>
<p>from beginning of line ^</p>
<p>take any amount of whitespace [[:space:]]</p>
<p>then create a group containing anything \(.*\)</p>
<p>up to whitespace at the end of the line [[:space:]]*$</p>
<p>replace this with the group \1 only (effectively removing the whitespace)</p>
<p>enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2009/02/sed-script-to-trim-leading-and-trailing-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yeah!!  Got Leopard alive!</title>
		<link>http://kirk.webfinish.com/2008/05/yeah-got-leopard-alive/</link>
		<comments>http://kirk.webfinish.com/2008/05/yeah-got-leopard-alive/#comments</comments>
		<pubDate>Sun, 18 May 2008 21:07:01 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=15</guid>
		<description><![CDATA[&#62;&#62;Found a post on the ALC662 chip here. It should work with the patcher found here. Will post later if it worked. It did! The current settings are: NVinject 128 MB MBR hard disk partition Darwin MBR BootLoader nForce 2/3/4/5 I had to break down and stick in an old RTL8139 network card that I [...]]]></description>
			<content:encoded><![CDATA[<p>&gt;&gt;Found a post on the ALC662 chip <a title="ALC662 Codec dump" href="http://forum.insanelymac.com/index.php?showtopic=79929&amp;pid=605582&amp;mode=threaded&amp;start=#entry605582" target="_blank">here</a>.  It should work with the patcher found <a title="Codec Mogrifier" href="http://forum.insanelymac.com/index.php?showtopic=32859" target="_blank">here</a>.  Will post later if it worked.</p>
<p>It did!</p>
<p>The current settings are:</p>
<p>NVinject 128 MB</p>
<p>MBR hard disk partition</p>
<p>Darwin MBR BootLoader</p>
<p>nForce 2/3/4/5</p>
<p>I had to break down and stick in an old RTL8139 network card that I had laying around.  Built in network MCP61 not working, RTL8139 card working fine.</p>
<p>Now on to XCode!</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2008/05/yeah-got-leopard-alive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

