<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-CA link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Further to the previous question about shell scripting and MySQL…<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>The script looks generally like this:<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='margin-left:.5in'><span lang=FR-CA>( commands; commands; commands; <o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span lang=FR-CA>cat &lt;&lt;__EOF__<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'>sql statements;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>sql statements;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>__EOF__<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p>&nbsp;</o:p></p><p class=MsoNormal style='margin-left:.5in'>find $basedir –args | while read VARIABLE; do<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>sed –i –e ‘s/xxx/yyy/gi’ –e ‘s/aaa/bbb/gi’ $VARIABLE<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>cat &lt;&lt; __EOF__<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>LOAD DATA INFILE ‘$VARIABLE’…;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UPDATE stuff…;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>__EOF__<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>) | mysql --user=… --password=… --host=… --database=… --batch<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>I didn’t really think about order-of-operations until it came back to bite me in the ass.  The script now has these comments in it.  Note carefully the last point in the comments, if you’re ever doing anything like this.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='margin-left:.5in'># The subshell allows us to start processing the mysql commands as soon<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># as they are echo(1)'d, improving parallelism dramatically.<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># Note that this does not cause magic to happen - commands will still<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># finish executing in order, so it's valid to, say, run sed(1) to pre-<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># process a file before echo(1)ing the LOAD DATA INFILE command to<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># MySQL.<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># In fact, due to stdio buffering issues, the MySQL commands probably<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># won't start executing until sometime shortly after they are sent;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># execution is definitely asynchronous, so keep in mind there are two<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># separate process &quot;pipelines&quot; happening.  So:<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># 1. each shell command may depend on previous shell commands having<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>#    executed;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># 2. each MySQL statement may depend on previous MySQL statements<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>#    having executed;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># 3. each MySQL statement may depend on previous *shell* commands<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>#    having executed;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'># 4. but each shell command ***MAY NOT*** depend on previous MySQL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>#    statements having executed!<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>-Adam<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>