<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../xsl/road-faq.xsl"?>

<rf:topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xsi:schemaLocation="http://schemas.roadintranet.org/road-faq-1 ../xsl/road-faq.xsd"  
   xmlns:rf="http://schemas.roadintranet.org/road-faq-1"
 title="Command line help"
 file="cmdline.xml"
 fileid="$Id: //main/2005/road/road-faq/xml/cmdline.xml#25 $$Change: 1140 $"
 fileChange="$DateTime: 2010/01/03 11:42:01 $$Author: bbarber $">
    <div><h4>Command line help  -- notes on using command shells from Road Intranet</h4></div>
    <rf:copyright>
        <a href="../../COPYING.txt">Copyright</a> (c) 2005-2010, C.B. Barber
    </rf:copyright>
      <rf:section id="win-cmd" title="Windows command line">
          <rf:item id="setup-username" title="Setup user name" date="Nov 2009" author="bbarber">
              A Unix-style user name does not contain spaces or upper-case letters.  It is not necessary.
             
              <p>To change your user name</p>
              <ul><li>
                  Go to the Users panel in Computer Mangement -- Control Panel->Adminstrative Tools->Computer Management->System Tools->Local Users and Groups->Users    
              </li><li>
                  Right-click the user and select Rename.  You may need to reboot afterwards.
              </li></ul>
          </rf:item>
          <rf:item id="setup-cmd" title="Setup the Windows command window" date="Oct 2005" author="bbarber">
         To configure a command window (e.g., Start->Run->cmd)
         <ul><li>
               Right-click on the title bar, Select Properties
         </li><li>
             Options->QuickEdit Mode -- Copy text by selecting->CR.  Paste text with right button
         </li><li>
            Options-> Buffer Size = 999
         </li><li>
            Font->Font>Lucinda Console
         </li><li>
            Layout->Screen Buffer->Height = 999
         </li><li>
            Layout->Window Size->Height = 55
         </li><li>
            Colors->Screen Background = White
         </li><li>
            Colors->Screen Text = Black
         </li><li>
            OK->Modify shortcut->OK
         </li><li>
             Consider changing the icon with right-click->Properties->Change Icon
                 <ul><li>
                     green tree -- Windows\System32\Shell32.dll
                 </li><li>
                     MsDOS -- Windows\System32\progman.exe
                 </li><li>
                     iconview -- list all of your icons
                 </li><li>
                 </li></ul>
         </li><li>
              To re-position to the command prompt -- Select  arbitrary text, Enter, Enter.    The
             first Enter copies the text.  The second Enter goes to cmd.exe and updattes the window.
         </li><li>
         </li><li>
         </li><li>
         </li><li>
             
             </li></ul>
      </rf:item>
<rf:item id="bash-util" title="Suggested utilities for Windows" date="July 2007" author="bbarber">

<p>    
    These utilities are useful on every machine.  
    If using road-bash, install them in <code>c:\bash\util</code>.  
    See also Scott Hanselman's  <a href="http://www.hanselman.com/tools">Tool list for Windows</a>.
</p>
    
    <div class="twocol">  <!-- NO blank li elements!  -->
        <div class="col leftcol">
            <h4>Collections</h4>
            <ul><li>
            <a href="http://www.cygwin.com">Cygwin</a>
            -- Unix on Windows
            </li><li>
            <a href="http://sourceforge.net/projects/gnuwin32/">GnuWin32</a> -- GNU on Windows
            </li><li>
            <a href="http://www.mingw.org">MINGW</a> -- GNU programming
            on Windows (includes MSYS)
            </li><li>
            <rf:iref item="setup-sysinternals"/>
            -- Windows systems internals
            </li><li>
            <a href="http://www.dmst.aueb.gr/dds/sw/outwit/">Outwit</a>
            -- Spinellis' collection of Windows utilities
            </li><li>
            <rf:iref item="powertoys"/>
            </li></ul>

            <h4>Sys-internals</h4>
            <ul><li>
                <a href="http://technet.microsoft.com/en-us/sysinternals/bb897332.aspx">AccessEnum</a> -- Enumerate access rights to directories and registry
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/processmonitor.mspx">Procmon</a> -- Monitor file, registry, and process activity
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psinfo.mspx">psinfo</a> -- Process info
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/tcpview.mspx">tcpview</a> -- Monitor TCP activity
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/autoruns.mspx">autoruns</a> -- List automatically started programs
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/handle.mspx">handle</a> -- List handles for files and objects
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/contig.mspx">contig</a> -- Defragment files and directories
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx">procexp</a>
            -- Process explorer
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psexec.mspx">psexec</a> -- Execute process on remote system
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psfile.mspx">psfile</a> -- List local and remote files
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psgetsid.mspx">psgetsid</a> -- List system IDs (SID) for names
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/pskill.mspx">pskill</a> -- Terminate process
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/pslist.mspx">pslist</a> -- List processes
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psloggedon.mspx">psloggedon</a> -- Who is logged on
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psloglist.mspx">psloglist</a> -- Display local and remote event logs
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/pspasswd.mspx">pspasswd</a> -- Change local or remote password
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psservice.mspx">psservice</a> -- Display and update local and remote services
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/psshutdown.mspx">psshutdown</a> -- Shutdown local or remote machines
            </li><li>
                <a href="http://www.microsoft.com/technet/sysinternals/utilities/pssuspend.mspx">pssuspend</a> -- Suspend a local or remote process
            </li></ul>


        </div>
        <div class="col rightcol">

            <h4>Windows</h4>
            <ul><li>
            </li><li>
                <a href="http://www.magma.ca/~wjr/PEview.zip">PEview</a> --  Exe and  .dll viewer
            </li><li>
            <rf:iref item="setup-depends"/> -- Dependency analysis for exe and dll
            </li><li>
            <rf:iref item="setup-logparser"/>
            -- Read log files, SQL, and Windows events
            </li><li>
            <rf:iref item="setup-mwsnap"/> -- Image capture
            </li><li>
                <a href="http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx">PowerCalc</a> -- Calculator
            </li><li>
                <a href="http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx">CmdHere</a> -- Start cmd window here, switch to <code>bash</code>
            </li><li>
                <a href="http://www.gbordier.com/">fileacl</a> -- Modify file permissions locally or remotely
            </li><li>
            <a href="http://www.mirekw.com/winfreeware">PINs</a> -- Password vault
            </li><li>
            <a
            href="http://users.forthnet.gr/pat/efotinis/programs/taskarrange.html">TaskArrange</a>
            -- Rearrange task bar
            </li></ul>

            <h4>Communications</h4>
            <ul><li>
                 <rf:iref item="setup-curl"/> --- command-line access to the Web.
            </li><li>
            scp, sftp, ssh -- Secure copy, ftp, and shell.  Included with PuTTY
            </li><li>
                <rf:iref item="setup-putty"/> -- Includes scp and ssh
            </li></ul>


            <h4>Text</h4>
            <ul><li>
                <a href="http://www.snapfiles.com/get/fontlist.html">FontList</a> -- Display sample fonts
            </li><li>
            <rf:iref item="setup-textpad"/> -- File editor.  Low-cost.   Recommended.
            </li><li>
            <a href="http://tidy.sourceforge.net">HTML Tidy</a> -- Clean up html, xhtml, and xml
            </li><li>
                <a href="http://notepad-plus.sourceforge.net">NotePad++</a> -- File editor
            </li></ul>

            <h4>Files</h4>
            <ul><li>
            </li><li>
            <a href="http://www.winzip.com/">WinZip</a>
            -- Zip format. Reads tar, tgz, etc.
            </li><li>
                <a href="http://www.winrar-download.info/">WinRar</a>
            -- Zip format
            </li></ul>

        </div>
    </div>

      </rf:item>
<rf:item id="setup-sysinternals" title="Setup SysInternals" date="Nov 2005" author="bbarber">
              <p><a href="http://www.sysinternals.com">www.sysinternals.com</a> is an excellent source of
                  system utilities.  For quick debugging, add the following utilities to
                  Taskbar->Toolbars->Quick
                  Launch:  AccessEnum, procexp, procmon, tcpview.  Other useful utilities include
                  autoruns, handle, ps*.    Their
                  book contains a wealth of information, <rf:iref item="russME_2005" />.</p>
              <ul><li>
                  64-bit computers -- 64-bit computers need different versions of procmon.
              </li><li>
                  <a href="http://www.microsoft.com/technet/sysinternals/utilities/accessenum.mspx">AccessEnum</a> -- List all
                  security permissions for the file system
              </li><li>
                  <a
                      href="http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx">DebugView</a>
                  -- Watch the debug output.
              </li><li>
                  handle -- display open handles for a process.  Useful for identifying <code>in use</code> errors, but it does not identify indexers and virus scanners.    Handles are also visible through procexp <rf:iref item="russME_2005" page="136-137, 141"/>
              </li><li>
                  <a
                      href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx">procexp</a>  -- Process explorer, and everything else
                  
                  <p>Set up symbols for Process Explorer</p>
                  <ul><li>
                      Install Debugging Tools for Windows <rf:iref item="setup-debugging"/>
                  </li><li>
                      procexp->Options->Configure Symbols->dbghelp path -- <code>C:\Program Files\Debugging Tools for Windows\dbghelp.dll</code>
                  </li><li>
                      procexp->Options->Configure Symbols->Symbols path --
                      <code>srv*D:\Download\Symbols*help://msdl.microsoft.com/download/symbols</code>.    For details, see <a
                          href="http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx">Debugging
                      Tools and Symbols</a>.
                      <rf:iref item="russME_2005" page="11, 28"/>
                  </li><li>
                      Process->Properties -- Show the environment, security, .NET counters for running processes
                  </li><li>
                  </li><li>
                  </li><li>
                  </li><li>
                      
                  </li></ul>
                  <p>Get a stack trace with Process Explorer</p>
                  <ul><li>
                      Open the process properties -- Select a process and right-click for the
                      Properties menu
                  </li><li>
                      Select the <code>Threads</code> tab.  Take a screen shot.
                  </li><li>
                      Press the <code>Stack</code> button
                  </li><li>
                      Select all of the lines (using Shift-click) and press <code>Copy</code>
                  </li><li>
                  </li><li>
                  </li><li>
                  </li><li>
                  </li><li>
                      
                  </li></ul>
              </li><li>
                  <a
                      href="http://www.microsoft.com/technet/sysinternals/utilities/processmonitor.mspx">ProcessMonitor</a>
                  -- combines regmon and filemon with extensive process monitoring.
                  <rf:iref item="russME_2005" page="192-196, 711-717"/>
              </li><li>
                  autoruns -- display programs to automatically run <rf:iref item="russME_2005" page="273-274"/>
              </li><li>
                  pagedefrag -- Improve memory performance, defragment the paging file
              </li><li>
                  psexec -- launch programs as Local System account, etc.  <rf:iref item="russME_2005" page="491"/>
              </li><li>
                  psgetsid -- view account security IDs (SID)  <rf:iref item="russME_2005" page="496-497"/>
              </li><li>
                  pskill -- kill local and remote processes by pid or name.  [Oct 2006] Does not work in
                  perl via system().
              </li><li>
                  streams -- view alternate streams associated with a file  <rf:iref item="russME_2005" page="721"/>
              </li><li>
                  pipelist -- view named pipes.  view activity with filemon  <rf:iref item="russME_2005" page="809-811"/>
              </li><li>
                  Winobj -- display system objects  <rf:iref item="russME_2005" page="124-134, 145-149, 552, 560, 621 "/>
              </li><li>
                  tdimon -- view TCP and UDP activity  <rf:iref item="russME_2005" page="824"/>
              </li><li>
                  Tokenmon -- monitor
                  security activity (no longer available from SysInternals)
              </li></ul>   
          </rf:item>
            <rf:item id="setup-bat" title="Setup Microsoft bat files" date="Aug 2005" author="bbarber">
              <p>Microsoft bat files are command-line scripts inherited from MS-DOS.    They are
              particular useful for scheduled tasks and shared scripts.</p>
                
              
              <ul><li>
                  Bash -- Bash is a better scripting environment than bat files (<rf:iref item="setup-bash"/>,
                  <rf:iref item="setup-cygwin"/>).     If you need 
              programmatic scripts, consider <rf:iref item="setup-wsf"/>, Javascript, Perl, Groovy,
                  and Windows Power Shell.
              </li><li>
                  <rf:iref item="stanWR_2004a"/> -- Documentation for <code>bat</code> files.  Use
                  chapters 2 and 3.  See the Appendix for a command reference (including
                  <code>IF</code> and <code>FOR</code>).
              </li><li>
                  @echo off -- If <code>@echo off</code> is the first line, then executed commands
                  are not echoed to stdout.
             </li><li>
                      :: comment -- Use '::'  or '::*' for comment blocks.  Unlike <code>rem</code>, they are
                  not echoed by default.
              </li><li>
                      goto :eof -- Exit this bat file.  Available under Win 2000, Win Server 2000,
                      and later operating systems.  Not tested on previous operating systems.
                  </li><li>
                      call :label -- Invoke an internal subroutine at label <code>:label</code>.  
                      Exit the subroutine with <code>goto :eof</code>.
                  </li><li>
                      cmd -- Enters a new instance of the command shell.
                  </li><li>
                      pause -- Displays the message <code>Press any key to continue . . .</code>.
                  </li><li>
                      wait n -- To wait 1000 milli-seconds, try <code>ping -n 1 -w 1000 1.1.1.1 >NUL 2>&amp;1
                      2>&amp;1</code> .   This command does not always wait.  
                      If you turn on quick-edit, <rf:iref
                              item="setup-cmd"/>, try
<pre>    @echo -- 
    @echo -- ALL DONE.  To retain this window, use the mouse and highlight a region.
    @echo --
    ping -n 1 -w 20000 1.1.1.1 >NUL 2>&amp;1
</pre>
                  </li></ul>
            </rf:item>
          <rf:item id="setup-curl" title="Setup cURL" date="May 2008" author="bbarber">
              <p><a href="http://curl.haxx.se/">cURL</a> (<a href=" http://curl.haxx.se/docs/manpage.html">man</a>)
                  is a Windows and Unix utility for URLs.  
               See <a href="http://www.fiddlertool.com">Fiddler2</a> for a graphical interface on Windows.</p>
              <ul><li>
                  SSL -- Download <code>libeay.dll</code> for SSL access
              </li><li>
                  Cookies -- Options <code>-b cookie.txt -c cookie.txt</code> reads cookies from cookie.txt and writes them back to cookie.txt when done.
              </li><li>
                  Redirects -- Option <code>--location</code> follows redirects
              </li><li>
                  Headers -- Option <code>-v</code> shows the headers sent to the web server.  Option <code>-H ...</code> adds headers to the request.  Option <code>-D -</code> displays the result headers.
              </li><li>
                  Examples -- Use quotes around http's, otherwise '&amp;' will get processed by the shell.
                  <pre>
                  # Show headers for an image --  curl -I  'http://frontline.images.tickets.com/images/tdc_logo_134_48.png'
                  # Show raw output -- curl -i  'http://frontline.images.tickets.com/images/tdc_logo_134_48.png' | strings | head -20
                  # Send a cookie --  curl -b "01AI=CT" -I http://frontline.images.tickets.com/images/tdc_logo_134_48.png'
                  # Write headers to file.txt -- curl -D file.txt 'http://www.google.com'
                  # Follow redirects and track cookies use -- curl --location -b cookies.txt -c cookies.txt
                  </pre>
              </li><li>
               </li></ul>   
          </rf:item>
          <rf:item id="setup-wsf" title="Setup Windows Script Files" date="Jan 2008" author="bbarber">
              <p>Microsoft's preferred scripting language is VBScript embedded in Window Script
                  Files.   See <a href="http://msdn2.microsoft.com/en-us/library/15x4407c.aspx"
                      >Using Windows Script Files</a>.</p>
              <ul><li>
                  Excel/Word object model -- See the VBScript reference section of the help
                  documentation.
              </li><li>
                  FileSystemObject -- Access the Windows file system.  See
                  <a href="http://msdn2.microsoft.com/en-us/library/d6dw7aeh(VS.85).aspx"
                      >FileSystemObject Basics</a> (MSDN).
              </li><li>
                  VBScript -- VBScript is the standard scripting language.  JScript is an
                  alternative.
                  See <a href="http://msdn2.microsoft.com/en-us/library/d1wf56tt(VS.85).aspx"
                      >VBScript Language Reference</a>.
              </li><li>
                  objExcel.DisplayAlerts = False --- Automatically select the default choice for 
                  dialog boxes.
              </li><li>
                  Workbook_Open -- The Workbook_Open macro executes on document open.  
                  Edit it from <code>Tools->Macro->Visual Basic->ThisWorkbook->View Code</code>
              </li><li>
              </li><li>
              </li><li>
              </li><li>
                  
              </li></ul>
  Example .wsf file
  <pre>
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;job>
&lt;comment>
&lt;/comment>

&lt;runtime>
&lt;description>
    rtf-to-word.wsf -- Convert any Word file format to Word format
&lt;/description>

&lt;named
name="SourceDir"
helpstring="Arg 0 is full path to source directory"
type="string"
required="true"
/>


&lt;example>

&lt;/example>
&lt;/runtime>

&lt;script language="VBScript">
&lt;![CDATA[

Dim source
source = WScript.Arguments.Item(0)

REM WScript.Arguments.ShowUsage 

Set objWord = CreateObject("Word.Application")

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(source)
Set files = folder.Files

If files.Count &lt;> 0 then
        For Each file In files
                If InStr(file.Path, "~") = 0 and InStr(file.Path, ".rtf") &lt;> 0 then
                        Rem WScript.Echo("File -- " + file.Path + " ~ " + CStr(InStr(file.Path, "~")))
                        Set objDoc = objWord.Documents.Open(file.Path)
                        dest = Replace(file.Path, ".rtf", ".doc")
                        Rem WScript.Echo("Dest -- " + dest)
                        objDoc.SaveAs dest, wdFormatDocument
                        objDoc.Close
                End If
        Next
End If

objWord.Quit


]]&gt;
&lt;/script>
&lt;/job>
        </pre>
          </rf:item>
      
        
          <rf:item id="cmd-useful" title="Windows commands" date="Sept 2005" author="bbarber">
              <p>  Microsoft's <a
                  href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx">documentation</a> and  ss64's 
                  <a href="http://www.ss64.com/nt/">documentation</a>.
                  For
                  Windows 2000, see <a
                      href="http://www.petri.co.il/download_free_reskit_tools.htm">Windows 2000 Resource
                      Kit tools</a>. </p>
              <ul><li>
                  assoc, ftype -- manage file associations with applications <rf:iref item="stanWR_2004a" page="19"/>
              </li><li>
                  cacls, dcgpofix, gpupdate -- Access control list for a file, default group policy, group policy update  <rf:iref item="stanWR_2004a" page="344, 346, 359"/>
              </li><li>
                  chkdsk, chkntfs, recover, sfc -- Check disk, recover readable info, scan/verify system  <rf:iref item="stanWR_2004a" page="161-164, 368, 373"/>
              </li><li>
                  cipher -- encryption of files and directories  <rf:iref item="stanWR_2004a" page="345"/>
              </li><li>
                  cmd -- Command shell <rf:iref item="stanWR_2004a" page="15-56"/>. 
              </li><li>
                  compact, expand --Compaction of NTFS files  <rf:iref item="stanWR_2004a" page="346, 356"/>
              </li><li>
                  defrag -- Defragment the C drive<rf:iref item="stanWR_2004a" page="164-166"/>
              </li><li>
                  diskpart, format, convert, label -- Disk partitioning and configuration <rf:iref item="stanWR_2004a" page="141-157, 168-180"/>. .
              </li><li>
                  driverquery, systeminfo, nlsinfo, gettype -- system information, local and remote, OS configuration <rf:iref item="stanWR_2004a" page="84, 358, 374"/>
              </li><li>
                  dsadd, dsget, dsmod, dsmove, dsquery, dsrm, movetree -- Active directory management  <rf:iref item="stanWR_2004a" page="199-266, 348-354"/>
              </li><li>
                  eventquery, eventquery, eventcreate, eventtriggers, eventvwr -- Event Logger  <rf:iref item="stanWR_2004a" page="103-118, 355-356"/>
              </li><li>
                  freedisk -- Check for free space  <rf:iref item="stanWR_2004a" page="358"/>
              </li><li>
                  fsutil -- File System utility  <rf:iref item="stanWR_2004a" page="158-160"/>
              </li><li>
                  ipconfig, arp -- TCP/IP configuration, DNS mapping <rf:iref item="stanWR_2004a" page="308, 343, 359"/>
              </li><li>
                  ipconfig /registerdns -- reregister DNS settings and report errors to event log
              </li><li>
                  msconfig -- System Configuration Utility
              </li><li>
                  memmonitor, pfmon, memtriage -- Memory and page fault monitor <rf:iref item="stanWR_2004a" page="133-138"/>. .
              </li><li>
                  mountvol --Mount disk volume  <rf:iref item="stanWR_2004a" page="360"/>
              </li><li>
                  net, nbtstat, netstat, route -- network management, Netbios status, network status, routing tables <rf:iref item="stanWR_2004a" page="244-245, 361-365, 369"/>. .
              </li><li>
                  netsh --Network Services shell <rf:iref item="stanWR_2004a" page="297-342"/>. .
              </li><li>
                  ping, pathping, tracert -- ping server, trace a path, traceroute  <rf:iref item="stanWR_2004a" page="366, 375"/>
              </li><li>
                  taskmgr, pmon, qprocess, tasklist, taskkill, tskill -- Process and task management <rf:iref item="stanWR_2004a"
                      page="119-132, 374"/>.   qprocess only shows Applications.   A better choice is <code>procexp</code> from <rf:iref item="setup-sysinternals"/>.
              </li><li>
                  printdriverinfo, splinfo, prnmngr, prnport, prncnfg, prnjobs, prnqctl -- Printer drivers, spool information, printer management, printer ports, printer configuration, printer jobs  <rf:iref item="stanWR_2004a" page="267-295"/>
              </li><li>
                  RAID configuration -- <rf:iref item="stanWR_2004a" page="181-195"/>
              </li><li>
                  reg -- Registry access <rf:iref item="stanWR_2004a" page="85-92, 368-369"/>.  
              </li><li>
                  regsvr32 -- Register DLLs  <rf:iref item="stanWR_2004a" page="369"/>.   See <a
                      href="http://support.microsoft.com/kb/249873/EN-US/">Explanation of Regsvr32</a>
               </li><li>
                  <a href="http://www.ss64.com/nt/robocopy.html">robocopy</a> -- Replacement for xcopy from <a
                      href="http://www.microsoft.com/downloads/thankyou.aspx?familyId=9d467a69-57ff-4ae7-96ee-b18c4790cffd"
                      >rktools.exe</a>.   Works with UNC pathnames.
             </li><li>
                  runas -- Run a program as a user  <rf:iref item="stanWR_2004a" page="369"/>
              </li><li>
                  sc -- System Services <rf:iref item="stanWR_2004a" page="92-100, 370-371"/>
              </li><li>
                  schtasks -- Task Scheduler <rf:iref item="stanWR_2004a" page="57-80, 371-372"/>.   By default tasks timeout after 72 hours.  Use properties to change the timeout.  Periodically check the log file, %SystemRoot%/Tasks/Schedlgu.txt.  
                  Consider using crontab from cygwin.
              </li><li>
                  setx -- update Windows envrionment.  <rf:iref item="stanWR_2004a" page="18"/>
              </li><li>
                  shutdown --Shutdown local and remote systems <rf:iref item="stanWR_2004a" page="101-102, 373"/>
              </li><li>
                  start -- Start a new command shell  <rf:iref item="stanWR_2004a" page="374"/>
              </li><li>
                  subst -- Substitute a path to a drive letter  <rf:iref item="stanWR_2004a" page="374"/>
              </li><li>
                  takeown -- Give file ownership to adminstrator  <rf:iref item="stanWR_2004a" page="374"/>
              </li><li>
                  timeit, kernrate, ntimer -- performance analysis.  See also time.exe in cygwin
              </li><li>
                  title -- Set title for window  <rf:iref item="stanWR_2004a" page="375"/>
              </li><li>
                  tsadmin (Terminal Services Manager) -- View and manage users connected to Windows
                  Server.
              </li><li>
                  winmsd, msinfo32 (System Information) -- Provides access to system, network, and
                  hardware, and application information.
              </li><li>
                  whoami -- Log on and security info  <rf:iref item="stanWR_2004a" page="376"/>
              </li><li>
                  Xcacls -- control file permissions.  See the improved <a href
                      ="http://www.microsoft.com/downloads/details.aspx?FamilyID=0ad33a24-0616-473c-b103-c35bc2820bda">xcalcs.vbs</a>
                  and Bordier's <a href="http://www.gbordier.com/">FileACL</a>.
              </li><li>
                  xcopy -- Directory and file copy included with Windows [robocopy is better].  For example
                  <pre>    xcopy Q:\QA\Smoke_test_results\Trunk-13.5\DOYLE\wsrun_ebook . /D:06-5-2007 /S /V /-Y /F </pre>
                  Recursively copies (/S) all files in Q:...wsrun_ebook to the current directory if they
                  were modified on or after 6/5/2006 (/D).  It prompts before overwriiting (/-Y),
                  displays the copied files (/F), and verifies the result (/V).  See <code>xcopy
                      /?</code> for other options.  
              </li></ul>
          </rf:item>
          
          <rf:item id="cmd-win" title="Windows command line utilities" date="Jan 2006" author="bbarber">
              <ul><li>
              </li><li>
                  <a href="http://www.spinellis.gr/sw/outwit/">outwit</a> -- Spinellis's interface to the
                  clipboard, registry, odbc, lnk links, event log
              </li><li>
                <a href="http://www.mingw.org">MinGW</a> -- Minimal GNU system for Windows software development.  
                Includes <a href="http://www.mingw.org/msys.shtml">MSYS</a>, a minimal GNU system on Windows.
              </li><li>
                  <a href="http://www.blat.net/">blat</a> -- Email client with attachments, html, etc.
                  (freeware).  
                  <ul><li>
                  <code>blat -h</code> -- help message (and an error status, <code>$?=1</code>)                     
                  </li><li>
                      Testing blat -- The first argument to blat is a text file.  For quickly
                      testing blat use '-', e.g., 
                      <pre>    echo "Test message" | blat - -s Testing -t bbarber@xyz.com</pre>
                  </li><li>
 .                 Profile -- Before using blat, you need to create a profile,
                  <code>blat -install SMTPHost SenderEmail [TryCount SMTPPort-25 ProfileName]</code>
                  (e.g., <code>blat -install 65.213.82.45 smoketest@%COMPUTERNAME% 5 25</code>.
                  Place this command in <code>blat_init.bat</code> for easy setup.
                  </li><li>
                    unexpected error 10053 from winsock -- If this error appears in the log file (blat.log)
                      and if you use McAfee VirusScan Enterprise 8.0.0 with firewall you should stop
                      blocking port 25.   Go to the McAfee system tray  <code>Console->
                      Access Protection -> Port Blocking</code> and uncheck port 25. It is labeled
                      "Prevent mass mailing worms from sending email."
                  </li><li>
                  </li><li>
                  </li><li>
                  </li></ul>
              </li><li>
                  <a
                      href="http://www.beyondlogic.org/solutions/processutil/processutil.htm">process.exe</a>
                  (BeyondLogic)  -- list and kill processes.  <code>process -q</code> sends a quit message followed
                  by process kill after a minute time out.   
              </li><li>
                  <a href="http://www.beyondlogic.org/porttalk/porttalk.htm">PortTalk</a> 
                  (BeyondLogic) -- direct
                  access to I/O ports.
              </li><li>
                  <a
                      href="http://www.beyondlogic.org/consulting/remoteprocess/BeyondExec.htm">BeyondExec</a>
                  (BeyondLogic) -- remote process management
              </li><li>
                  <a href="http://tidy.sourceforge.net">HTML Tidy</a> -- convert HTML to XHTML
              </li><li>
                  <a href="http://wix.sourceforge.net/">WIX</a> -- Windows Installer XML toolkit. 
                  Used by Microsoft Office,etc. to build msi installers.
              </li><li>
                <a href="http://www.gdargaud.net/Hack/Windows.html">Windows with Unix</a>
              </li></ul>
          </rf:item>
          
          <rf:item id="setup-logparser" title="Setup LogParser" date="Dec 2005" author="bbarber">
              <p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07"
                  >LogParser</a> is an excellent tool for processing
                  logs and any source of tabular information.</p>
              <ul><li>
                  logparser -h EXAMPLES -- Examples for using logparser
              </li><li>
              </li><li>
              </li><li>
              </li><li>
              </li><li>
                  
                  Directories (-recurse) -- Use -i:textline -recurse:-1 to grab the text for all files in a
                  directory hierarchy.  The "FROM ..." file pattern must include a * (e.g.,
                  <code>logparser -i:testline "select *
                      from singularity/errorlog.*" -recurse:-1</code>).
              </li><li>
                  -i:XML -- XML input uses MSXML and does not report line numbers on errors.   To identify
                  the error, load the XML file into IE.  
              </li><li>
                  High-bit ASCII -- MSXML and Logparser do not allow high-bit ASCII characters.   Firefox and
                  Oxygen show these files correctly.  To remove, use 
                    <pre>  cat file.xml | tr -c -d [:print:][:space:]</pre>  
                  To detect, use 
                  <pre>find . -type f | grep -v "'" | xargs -i egrep  -l '[^ -~[:space:]]'   "{}" </pre>
              </li><li>
                  XPath expression -- For <code>-i:xml</code>, the XPath expression identifies the root
                  node(s) only.  The remainder of XPath is not implemented.
              </li><li>
                  Multiple XML elements -- Each attribute will have its own name.  Use <code>fieldname
                      &lt;> null</code> to select individual records.  If different elements use the same
                  attribute names they are assigned a numeric suffix.    This makes the output schema dependent
                  on the actual input.
              </li><li>
                  select ... as ... -- If a column has the same name as a select, the column name is
                  used in a <code>where</code> clause.
              </li><li>
                  fields and types -- Use -h to view the fields and data types for an input file, e.g., <code>logparser
                      -h -i:xml test-file.xml</code>.  
              </li><li>
                  integer vs. string -- logparser distinguishes integer from non-integer
                  data.  If a field can be both integer and string (e.g., an ID), always convert it to
                  one type or the other before using SQL output.
              </li><li>
                  bulk load -- Do not use logparser for loading more than a million rows into a database. 
                  Use bcp and sed instead.
              </li><li>
                  Datetime field overflow -- This error occurs if you attempted to store a logparser
                  datetime field into an SQL Server smalldatetime.   It looks like a bug in logparser.
              </li></ul>
          </rf:item>

          <rf:item id="cmd-tools" title="Setup windows tools" date="Sept 2005" author="bbarber">
            <ul><li>
               Support tools -- Install Support/Tools/Suptools.msi (Windows Support Tools) from a Windows Server 2003 or XP Professional CD-ROM.  <rf:iref item="stanWR_2004a" page="11-13"/>
            </li><li>
               Rktools -- Install <a
                   href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD">Rktools.exe</a>
                  (Windows Server 2003 Resource Kit Tools) by download from Microsoft Windows Download Center <rf:iref item="stanWR_2004a" page="14"/>
            </li><li>
                Win 2000 Reskit -- Download 
                <a href="http://www.petri.co.il/download_free_reskit_tools.htm">Windows 2000
                    Resource Kit tools</a>.  For a discussion, see <a
                    href="http://www.microsoft.com/technet/community/columns/profwin/pw0102.mspx">Windows
                2000 Tips &amp; Tricks</a>.
             </li></ul>
      </rf:item>
      </rf:section>
    <rf:section id="unix-cmd" title="Unix Command Line" >

         <rf:item id="setup-bash" title="Setup Road-bash" date="July 2007" author="bbarber">
         <p><a href="../../../bash/doc/road-bash.html">Road-bash</a> is a portable Bash environment for Unix and Windows.  It consists of 
            shell scripts for initializing the Bash shell.  
         </p>
           <ul><li>
               Install <a href="http://www.qhull.org/bash/doc/road-bash.html">Road-bash</a> for Windows (zip) or Unix (tgz). 
           </li><li>
                If the command prompt is "sh-3.1$" -- The bash startup script, <code>bash/etc/road-bashrc.sh</code> did
                not run.  Try sourcing the file directly.  Check <code>etc/profile</code>.  It is executed before
                road-bashrc.sh
           </li><li>
                road-test.sh -- Run this command to test your bash installation.  Road-bash
                requires bash 2 or later, preferably installed as <code>/bin/sh</code>.
           </li><li>
                egrep -- If egrep is not installed (grep -E), the <code>find</code> commands
                will not work.  As a workaround, add <code>alias egrep=grep</code> to your
                .bashrc and rewrite the function <code>finda</code> in <code>road-bashrc.sh</code>.
           </li><li>
               <a href="http://www.linuxcommand.org/man_pages/locate1.html">slocate, locate</a> -- Fast filename lookup using a database refreshed nightly via 'updatedb'.  On Unix systems, updatedb runs quickly.  Locate is available for MSYS and Road Bash 
               under 'MSYS findutils' in <a href="http://sourceforge.net/projects/mingw/files/">MinGW Downloads</a>.  You need to add '/usr/local/bin' to the PATH variable in 'updatedb'.  
               Add 'SEARCHPATHS=/c' to your environment variables.  It takes a while to index your files.
           </li><li>
                sed -r -- If <code>sed</code> does not support extended regular expressions, consider
                upgrading.   You should use <code>sed -r</code> for scripts.
            </li><li>
                //option -- MSYS bash requires //option for Windows
            </li><li>
            start/cmd -- Do not start bash with 'start /m' or 'cmd /k'
        </li></ul>
         </rf:item>
          
       <rf:item id="unix-util" title="Unix utilities" date="Jan 2006" author="bbarber">
       <p>For complete, concise documentation of Unix commands, see 
            <rf:iref item="sievE_2003"/> 
          See also <rf:iref item="setup-bash"/>
            and <rf:iref item="setup-cygwin"/>
         </p>
           <ul><li>
                <a href="http://www.spinellis.gr/sw/unix/fileprune/">FilePrune</a> -- Spinellis's
                backup file prune utility
           </li><li>
                <a href="http://www.spinellis.gr/sw/unix/socketpipe/">socketpipe</a> -- Spinellis's
                efficient remote command execution.  Uses ssh for remote login and an unencrypted data pipe.
            </li><li>
                <a href="http://www.spinellis.gr/sw/unix/stat/">stat</a> -- Spinellis's interface to
                stat(2) for detailed information about file status (not tested under cygwin)
            </li><li>
                <rf:iref item="sed-faq"/> (here) -- hints on using the Unix stream editor
            </li><li>
                <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">PuTTY</a>
                -- A good terminal emulator for Windows.  Includes ssh, scp, and sftp (<rf:iref item="setup-putty"/>)
            </li><li>
                <a href="http://software.jessies.org/terminator/">Terminator</a> -- A java terminal emulator 
                modeled on Mac OS Terminal.
            </li><li>
            </li><li>
                
            </li></ul>
        </rf:item>
        
        <rf:item id="bash-faq" title="Bash FAQ" date="Jan 2006" author="bbarber">
      <ul><li>
      </li><li>
          verbose -- If a bash script misbehaves, invoke it with the --verbose flag (e.g., <code>bash --verbose script-file</code>.  Bash will echo each command line.
      </li><li>
          PID -- Use <code>$$</code> for the current process ID.  Good for unique IDs for log
                files.
      </li><li>
          .bash_profile -- For new bash login sessions, $HOME/.bash_profile is sourced after /etc/profile.  It is ignored for interactive sub-shells (e.g., executing 'bash' or creating a shell in emacs).
          Use .bash_profile for one-time initialization (e.g., $PATH).
      </li><li>
      </li><li>
                stderr redirect -- To redirect stderr to a file, use <code>2>stderr-file</code>.  To
                redirect stderr and stdout to a file, use <code>&gt;stdout-file
                    2&gt;&amp;1</code> (order is important).
            </li><li>
                wildcard expansion -- Bash expands wildcards in file lists (also called
                <i>globbing</i>) <rf:iref item="newhC_1998" page="10-13"/>.
                For example, <code>ls *.txt</code> expands to all .txt files in the
                current directory.  Expansion happens <i>before</i> calling the command.  If there are
                too many filenames in a directory, use 'echo' or 'find' with 'xargs'.  
                <p>The wildcards are</p>
                <ul><li>
                    * -- Any sequence of characters, including '.'
                </li><li>
                    ? -- Any single character
                </li><li>
                    [a-z] -- Any lowercase character
                </li><li>
                    [!A-Z] -- Anything but an uppercase character
                </li></ul>
                
            </li><li>
                brace expansion -- Brace expansion (e..g., <code>ls *.[c,h,o}</code>) is similar to
                wildcard expansion.  It expands arbitrary strings.  The braces may be nested.
                <rf:iref item="newhC_1998" page="14"/>
            </li><li>
                globstar expansion -- zsh and ksh93 support ** to include all subdirectories.  If so
                <code>ls -1rt **/*.txt</code> lists all text files in any subdirectory in order of
                modification.  There isn't an equivalent command in bash (including extglob).
            </li><li>
            </li><li>
            </li><li>
                ex -- Command-line editor from 'vim'.  Use 'ex' to edit files
                in place.   For example the following line inserts new text into all wsrun log files.
                <pre>    findf wsrun_result.log | xargs -i ex -c '1,$s/&amp;testrun testsuiterun/&amp;testrun codeline="13.1.3" testsuiterun/' -c 'wq'  "{}"</pre>
            </li><li>
                termcap -- The files <code>/etc/termcap</code> and
                <code>~/.termcap</code> define ncurses for older terminal interfaces (e.g., cygwin's <code>less</code> command).
                Most programs use <code>terminfo</code> instead.  To regenerate the termcap file, use
                <pre>    infocmp -C >> ~/.termcap</pre>

            </li><li>
                --initfile -- To execute a command that depends on Road Bash, use 
                <pre>bash --init-file /etc/road-home.bashrc -i -c "your commands"</pre>
            </li><li>
                
            </li></ul>
        </rf:item>
        <rf:item id="bash-hints" title="Hints on using Bash" date="July 2007" author="bbarber">
      <div class="twocol">  <!-- NO blank li elements!  -->
        <div class="col leftcol">

            <h4>Essentials</h4>
            <ul><li>
            Linux in a Nutshell -- Complete documentation of bash, sed, emacs, vim, etc.
            </li><li>
            Spaces -- Bash requires spaces around !, [[ ... ]], and operators
            </li><li>
            "$var" -- Expand $var in quotes if it may contain spaces.  Quotes are not needed with [[...]].
            Does not work for 'for f in x*y; do ... done'
            </li></ul>

            <h4>Errors</h4>
            <ul><li>
            : command not found -- On Unix and Cygwin, shell scripts must use \n instead of \r\n.
            </li><li>
            syntax error near unexpected token `(' -- If '(' is in a string, a previous string is
            missing a quote ("...").  Use
            divide-and-conquer to locate the error.
            </li><li>
            Unexpected end of file -- 
            Use divide-and-conquer by inserting <code>exit</code> (<code>cat -</code>.if sourced). 
            Check for required spaces around [[, ]], {, }, and operators.  
            Check if...; then..fi.  Check &lt;&lt;HERE. 
            </li><li>
            Unexpected end of file, missing quote -- Use divide a conquer with a string containing
            left parentheses (e.g., echo "reports error () if previous mismatched quote.").
            </li></ul>

            <h4>Variables</h4>
            <ul><li>
            ${var} or $var -- Value of var
            </li><li>
            ${var/*x/z} or ${var/*x} -- Substitute or delete matching filename pattern
            </li><li>
            $$ -- process ID
            </li><li>
            $LINENO -- current line number

            </li><li>
            $* vs $@ -- $* is all args, $@ is $1 $2...Same as %* in batch files
            </li><li>
            ${num_new// } -- Delete all spaces (e.g., the output of <code>wc -l</code>)
            </li><li>
            ${SKIPPING##*$SKIP*} -- Empty if $SKIP is in $SKIPPING (## removes longest prefix with wildcard *)
            </li></ul>

            <h4>Avoid</h4>
            <ul><li>
            `...` -- Use <code>$(...)</code> to execute commands within strings
            </li><li>
            [ ... ] -- Use <code>[[ ... ]]</code> for conditional expressions
            </li><li>
            n=n+1 -- Use <code>$((n+1))</code> for computation
            </li><li>
            n == 5 -- Use <code>n -eq 5</code> for numeric comparison
            </li><li>
            \r\n -- Use an editor that handles Unix line endings.  Use $EOL for \r\n.
            </li><li>
            Save during execute -- Do not modify scripts while running them,  Bash rereads after each <code>if..then..fi</code>.
            </li></ul>
            
        </div>
        <div class="col rightcol">
            <h4>Functions</h4>
            <ul><li>
            function name() { ... } -- Define name as a function.  Must be space before {
            </li><li>
            $(pwd) -- Execute pwd.  Better than back-ticks.
            </li><li>
            $(type -p xyz) -- True if xyz is a program, function, or alias. 
            </li><li>
            exec /bin/less "$@" -- Definition of /bin/more
            </li><li>
            eval is easily hacked -- Be extra careful of ;, ', and " in values.
            </li><li>
            wsf -- Invoke Windows wsf scripts from within if...then...fi.  It waits until done.
            </li><li>
            Delete non-printing characters -- `echo "$f_file" | sed -r 's/[^ -~]//g'`
            </li></ul>

            <h4>Conditionals</h4>
            <ul><li>
            $? -- Exit status of previous command (OK if 0)
            </li><li>
            if ! cmdA &amp;&amp; cmdB || cmdC; then ... fi -- True if $? is 0
            </li><li>
            if [[ test ]]; then ... fi -- Executes if test succeeds.  Must be spaces around [[ and before ]].
            </li><li>
            if [[ ${url/*xyz*} ]]; then .. fi -- True if $url contains xyz
            </li><li>
            if [[ ${url:0:4} == "404;" ]]; then .. fi -- True prefix 
            </li><li>
            if [[ $num -ne 0 ]]; then...fi -- Use -ne, -eq, for numbers, !=, == for strings
            </li></ul>

            <h4>Repetition</h4>
            <ul><li>
            for f in $files; do ... done -- Do not use "$files"
            </li><li>
                To parse lines -- To parse lines instead of words, 
                <pre> OLDIFS=IFS; IFS=$'\012' ; for f in $(find ...); do </pre>
            </li><li>
                Looping over find -- 
                <pre>  find . -type f -name "*.log" | while read file; do </pre>
            </li></ul>

            <h4>Bash 2.0 vs 3.1</h4>
            Portable scripts should support 2.0.  Require Bash 3 for =~ matching.
            <ul><li>
            No '-' in function names -- Bash 2.0 does not '-' in function names.
            </li><li>
            ${x=~s///} -- 3.1 supports Perl regular expressions
            </li><li>
            $file == x*y.exe -- 3.1 supports file glob tests
            </li><li>
            () -- In 2.0, do not use () in echo -e commands
            </li><li>
            "${value//\\%20/ }" -- Bash 2.0 requires '\\' within ".  In 3, 
            replace every %20 with a space by
            "${value//\%20/ }"
            </li><li>
            "${f//\\\'/}" -- Delete all ' for Bash 2.0.  In Bash 3 use "${f//\'/}"
            </li><li>
            ${FUNCNAME[1]} -- The caller's name in Bash 3 (the call stack)
            </li><li>
            var-name -- Bash 3 allows '-' in function and variable names.
            </li></ul>
        </div>
    </div>

        </rf:item>
        <rf:item id="sed-faq" title="sed notes" date="Jan 2006" author="bbarber">
           <p>Sed is the Unix stream editor.  It is included with cygwin.  For documentation, 
               see          <a
                   href="http://www.gnu.org/software/sed/manual/sed.html">Manual</a>,
               <a href="http://www.grymoire.com/Unix/Sed.html">Tutorial</a>, and
               <rf:iref item="sievE_2003"/>.
           </p>
           <ul><li>
               tabs - In patterns, use literal tabs instead of <code>\t</code>.  The later may be used
               in replacement patterns
           </li><li>   
               one or more -- 'sed' does not support '+'.   Make do with '*'.
           </li><li>
               awk -- The awk program is much faster than sed for transforming space-delimited data.
           </li><li>
           </li></ul>
           Partial listing of sed commands
           <ul><li>
               1 -- Apply the command to the first line
           </li><li>
               $ -- Apply the command to the last line
           </li><li>
               /.../ -- Apply the command to all lines matching this pattern
           </li><li>
              { ... } -- Braces indicate a block of commands
           </li><li>
               a -- Append text after this line.
           </li><li>
               b -- Print the current line and start over again.
           </li><li>
                b_restart -- Unconditional branch to the line labeled <code>:_restart</code>
            </li><li>
                d -- Delete the current line and read in a new one.   Start over again.
            </li><li>
                 h -- Copy the line into the hold space (i.e., sed's clipboard)
             </li><li>
                 i -- Insert text before this line
             </li><li>
                 N -- Read the next line, appending it to the current line with <code>\n</code>
             </li><li>
                 s/.../.../ -- Substitute the second pattern for instances of the first pattern.  A
                 'p' suffix prints matched lines.  A 'g' suffix repeats the substitution on the
                 current line.
             </li><li>
                 x -- Exchange the hold space for the current line
             </li><li>
                 
             </li></ul>
       </rf:item>
       <rf:item id="multi-line-sed" title="Processing multi-line records with sed" date="Dec 2005" author="bbarber">
         <p>To process text files of multi-line records use 'sed' from 
             <rf:iref
                 item="setup-bash"/> or <rf:iref
            item="setup-cygwin"/>.   Use <code>sed -r -f script-file.txt</code> where
            <code>script-file.txt</code> defines transformations for matching lines.  Option -r uses
             the simpler egrep regular expressions.  
             If you tag each processed line, <code>grep -v ...</code>
            will identify unprocessed lines.</p>
         <p>The following <code>sed</code> commands are particularly useful</p>
            <ul><li>
            b -- Skip the rest of the script file and print out the line.
            </li><li>   
            b-label -- Skip to the label, <code>:-label</code>
         </li><li>
            d -- Read the next line of text and restart the script
         </li><li>
            G -- Append the contents of the hold space with a \n separator
         </li><li>
            h -- Copy the current line to the hold space (like a paste buffer)
         </li><li>
            N -- Append the next line to the current line with a \n separator
         </li><li>
            p -- Print the line, useful for debugging
         </li><li>
            s/.../.../ -- Substitute one regular expression for another.  Use the 'g' suffix to make
            all substitutions.  Use <code>(...)</code> to identify
            substitution groups.  The '+' operator is not supported.   Prefer <code>[^"]*</code>
            to <code>.*</code> since the later takes the longest matching pattern.
            </li></ul>
         <p>For example, the following transfers a header line to the hold space and appends the
            hold space to matching lines</p>
         <blockquote><pre>
 /errorlog.txt *file ---/{
            s/.*\\([^\\]*)\\([^\\]*)\\([^\\]*)\\errorlog.txt file --- "([^"]*)".*/machine="\1" testsuite="\2" datetime="\3" file="\4"/
            s/file="(.*)\\([^\\]*)"/testfile="\2" file="\1\\\2"/
            s/datetime="([^_"]*)_([^_"]*)_([^-"]*)-([^."]*)\.([^"]*)"/builddate="\1-\2-\3" buildtime="\1_\2_\3-\4" run="\5"/
            h
            d
 }
 /columns in matrices not equal\./{
            N
            s/.*Test case ([^,]*).*Answer Number Columns == "*([^".,]*).*Test Number Columns == "*([^".]*).*$/LogError testcase="\1" error="WrongColumnNumber" ResultString="\2" TestString="\3" /
            b-appendHold
 }
 #append hold buffer to line and convert to xml
            :-appendHold
            G
            s/\n//g
            s/.*/&lt;\0\/>/
 }
         </pre></blockquote>
      </rf:item>
    </rf:section>
    <rf:section id="cygwin" title="Cygwin -- Unix on Windows">
        <rf:item id="setup-cygwin" title="Setup cygwin" date="Oct 2005" author="bbarber">
            <p><b>Cygwin</b> is an implementation of Unix on the Windows platform.  It contains
                hundreds of commands.  For
                documentation, see <rf:iref item="sievE_2003"/>.  Also consider <rf:iref item="setup-bash"/>.
                It includes MSYS, a minimal system derived from cygwin.</p>
            <p>To set up cygwin:</p>
            <ul><li>
                Download Setup.exe (Install Cygwin Now) from <a href="http://www.cygwin.com">www.cygwin.com</a>
            </li><li>
                Execute Setup.exe,  Install from Internet.  
            </li><li>
                Root = d:\cygwin; Install for All Users; Default Text File is DOS    
            </li><li>
                Local Package Directory = d:\cygwin\installers
            </li><li>
                Direct Connection, <code>http://mirror.mcs.anl.gov</code>  Other download sites should also work, but some of them are unavailable or out-of-date.
            </li><li>
                Click the 'View' button to see an alphabetical listing.
            </li><li>
                Add files by clicking 'Skip' in the 'New' column.  It displays to the current version.  
            </li><li>
                Consider skipping ash, adding bc, chere, cron, emacs, openssh.  Use ActiveState for
                perl.
            </li><li>
                Others to consider autossh, bashdb, emacs, file, inetutils, keychain, ruby, vim (with
                ex for bulk edit)
            </li><li>
                Click 'Next' to download and install the packages.
            </li><li>
                Reboot (if prompted)
            </li><li>
                Click on the Bash icon.  It invokes Bash, and initializes /home/userid.  
            </li><li>
                If there are problems, consider reinstalling cygwin from another mirror.  Sometimes
                a mirror will pick a bad copy of the software.
            </li><li>
                Textmode vs. binmode -- Unix uses LF to terminate lines while Windows uses CRLF and
                Macintosh using CR.   Cygwin tries to adjust for these problems (
                <a href="http://cygwin.com/cygwin-ug-net/using-textbinary.html">Using
                    text-binary</a>).   For example, bash will report odd errors for shell scripts
                if it gets the mode wrong.  Consider using the <code>mount</code> command to make
                a volume textmode.   
            </li><li>
                Copy /etc/bash* and /etc/skel/*
            </li><li>
                Click on the Bash icon.  It invokes Bash, and initializes /home/userid.  
            </li><li>
                Execute the following:
                <ul><li>
                </li><li>
                    mount c: /c ## ignore the warning /c does not exist
                </li><li>
                    mount d: /d ## and another drive letters you want accessible from cygwin
                </li><li>
                </li></ul>
            </li><li>
                If bash reports problems with passwd and group, login in as an administrator, and execute the commands
                <br/> mkpasswd -l -d > /etc/passwd; mkgroup -l -d >/etc/group
                <br/> It creates entries for all local users, domain users, local groups, and domain
                groups.  Change your home directory by editing  /etc/passwd.  Instead of
                //library/_userid_  use a personal folder such as  /home/userid or /d/cbb/myhome
            </li><li>
                If the prompt is "$", you haven't installed the /etc bash files.  To try again, use
                Explorer to delete your home directory, /d/cbb/myhome.
            </li><li>
                Configure the bash window using <rf:iref item="setup-cmd"/>.   
            </li><li>
                Add <code>cygwin\bin</code> to <code>Control
                    Panel->System->Advanced->Environment->PATH</code>.   If so, cygwin commands such
                as <code>ls</code> may be used from the Windows command shell.
            </li><li>
            </li><li>
            </li><li>
            </li><li>
                
            </li></ul>
            <p>To update cygwin:</p>
            <ul><li>
                The setup program changes rapidly, so it's not worth reusing.  Download a fresh copy from <a href="http://www.cygwin.com">www.cygwin.com</a>.
            </li><li>
                Repeat the procedure for installing cygwin. 
            </li><li>
                Cygwin uses the 'installers/' directory to keep track of what you have already installed.
            </li></ul>
            
            <p>Cygwin problems</p>
            <ul><li>
                Create directories with Explorer -- Cygwin and Explorer use slightly different
                security models.  Inherited permissions do not work for mkdir directories.  Use
                Explorer instead.  <rf:iref item="file-security"/>.
            </li><li>
            </li><li>
            </li><li>
            </li></ul>
        </rf:item>
        <rf:item id="bash-iis" title="Using bash with IIS" date="Dec 2007" author="bbarber">
            <p>To run bash scripts as part of IIS</p>
            <ul><li>
                Add <code>bash</code> to IIS -- Go to <code>Control panel->Administrative Tools->Internet
                    Information Services (IIS)->right-click your web site->Properties->Home
                    Directory->Application Settings->Configuration->Add</code>.  Set the Executable to
                <code>C:\bash\bin\bash.exe "%s" %s</code>.    Set <code>extension</code> to
                <code>.sh</code>    Check <code>Script engine</code> and
                <code>Check that file exists</code>
            </li><li>
                Windows Server 2003 -- IIS on Windows Server 2003 has more restrictive security settings than
                Windows XP.       Follow the instructions at  
                <a
                    href="http://support.microsoft.com/kb/150629/EN-US/">Configuring and testing a perl
                    script with IIS</a> (Microsoft) 
                and
                <a href="http://support.microsoft.com/kb/315122"
                    >"HTTP Error 404 ... when you request dynamic content with IIS 6.0</a>.
                Some mix of the following steps worked OK
                <ul><li>
                    Testing IIS on Server 2003 -- If IIS is not set up correctly, you just get a blank page, or a 404 error.  To test,
                    stop and start your your web site using IIS.  Apparently, you do not need to restart
                    the server or restart the IIS service.
                </li><li>
                   Enable bash scripts -- Enable bash scripts with <code>Internet Information Services
                            (IIS) Manager->Web Service Extensions->Add a new Web service
                            extension</code>.   Set the <code>Required files</code> to an
                           exact copy of the line used above for script engine (e.g., 
                    <code>C:\bash\bin\bash.exe "%s" %s</code>).  Double check that its status is
                    'Enabled'
                </li><li>
                    IIS requires a special registry setting
                    for CGI scripts.  Set
                    <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap\.sh</code>
                    to <code>C:\bash\bin\bash.exe "%s" %s</code>
                </li><li>
                </li><li>
                    
                </li></ul>
               </li><li>
                Execute permissions to cgi-bin -- Give '<code>Everyone</code>' Read, List, and
                Read Execute permissions to the cgi-bin directory.  Instead of Everyone, the IIS
                user may be sufficient
            </li><li>
                Enable scripts for the cgi-bin directory -- Using IIS, navigate to
                <code>cgi-bin->right-click->Properties</code> and 
                select <code>Execute permissions->Scripts
                    only</code>.  Disallow <code>Directory browsing</code>
            </li><li>
                cgi-bin/test.sh -- Create a simple test file 
                <pre> echo "Content-Type: text/plain" &amp;&amp; echo &amp;&amp; echo Hello World</pre>
            </li><li>
                
            </li><li>
                All scripts need to output the http headers, a blank line, and contents. 
                You need to initialize the bash environment first.  For example
                <pre>
                    source ../cgi-bin/roaddb-cgi-bin.sh
                    cat &lt;&lt;HERE
                    Content-Type: text/text; charset=ISO-8859-4
                    
                    &lt;html>
                    &lt;body>
                    This is file-not-found
                    &lt;/body>
                    &lt;/html>
                    HERE
                </pre>
            </li><li>
            </li></ul>
        </rf:item>
    </rf:section> 
   <rf:section id="cmd-ref" title="References" order="sorted">
       <rf:item id="newhC_1998" title="[newhC_1998] Learning the bash shell" date="Sept 2005" author="bbarber">
           <p>Newham, Rosenblatt, O'Reilly 1998</p>
           <p>Tutorial on writing shell scripts in bash.</p>
       </rf:item>
       <rf:item  id="sievE_2003" title="[sievE_2003] Linux in a Nutshell" date="Sept 2005" author="bbarber">
           <p>Siever, Figgins, Weber, O'Reilly 2003, ISBN 0-7356-1183-1</p>
           <p>Complete reference to Linux, bash, emacs, vi, sed, and gawk.  Much of it usable via 
                <rf:iref item="setup-bash"/> or <rf:iref item="setup-cygwin"/></p>
       </rf:item>
       <rf:item id="stanWR_2004a" title="[stanWR_2004a] Microsoft Windows Command-Line" date="Sept 2005" author="bbarber">
           <p>Stanek, Microsoft, 2004, ISBN 0-7356-1183-1</p>
           <p>Command line access to all things Microsoft.  Use in conjunction with cygwin or
               Road-bash.</p>
       </rf:item>
   </rf:section>
</rf:topic>

