<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://gilliath.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fgilliath.spaces.live.com%2fcategory%2fScripting%2b-%2bBatch%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Gilliath: Scripting - Batch</title><description /><link>http://Gilliath.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catScripting%2b-%2bBatch</link><language>en-US</language><pubDate>Mon, 06 Oct 2008 20:07:10 GMT</pubDate><lastBuildDate>Mon, 06 Oct 2008 20:07:10 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://Gilliath.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>226155696666371674</live:id><live:alias>Gilliath</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Compund command symbols</title><link>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!119.entry</link><description>&lt;font size=2&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;There are a few cases where I need a batch script to do one thing, and if it fails, do another. There is something that has been around since Windows NT 4.0 to help us create these conditional branches.&lt;br&gt;&lt;br&gt;The command shell supports running multiple commands on one line. You probably have seen this using the &amp;amp; symbol. The following is a table of compound command sybols and their use:&lt;br&gt;&lt;br&gt;Symbol                    Use&lt;br&gt;------------------------------------------------------------------------------------------&lt;br&gt;Cmd1 &lt;span style="font-weight:bold"&gt;&amp;amp;&lt;/span&gt; cmd2           Executes command &lt;span style="font-style:italic;font-weight:bold"&gt;cmd1&lt;/span&gt;, then command &lt;span style="font-style:italic;font-weight:bold"&gt;cmd2&lt;/span&gt;. &lt;br&gt;                             Additional commands can be added using additional ampersand symbols.&lt;br&gt;&lt;br&gt;Cmd1 &lt;span style="font-weight:bold"&gt;&amp;amp;&amp;amp;&lt;/span&gt; cmd2         Executes command &lt;span style="font-weight:bold;font-style:italic"&gt;cmd1&lt;/span&gt;, then executes command &lt;span style="font-weight:bold;font-style:italic"&gt;cmd2 &lt;/span&gt;only if &lt;span style="font-weight:bold;font-style:italic"&gt;cmd1 &lt;/span&gt;completed successfully.&lt;br&gt;&lt;br&gt;Cmd1 &lt;span style="font-weight:bold"&gt;||&lt;/span&gt; cmd2          Executes command &lt;span style="font-weight:bold;font-style:italic"&gt;cmd1&lt;/span&gt;, then executes command &lt;span style="font-weight:bold;font-style:italic"&gt;cmd2 &lt;/span&gt;only if &lt;span style="font-weight:bold;font-style:italic"&gt;cmd1 &lt;/span&gt;&lt;br&gt;                             did not complete successfully.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight:bold"&gt;( )&lt;/span&gt;                          Use parentheses to indicate the nesting of complex multi-command sequences.&lt;br&gt;------------------------------------------------------------------------------------------&lt;br&gt;&lt;br&gt;In effect, this helps us create an &lt;span style="font-weight:bold"&gt;AND &lt;/span&gt;and/or an &lt;span style="font-weight:bold"&gt;OR &lt;/span&gt;conditional branch in our scripts. &lt;br&gt;&lt;br&gt;Consider the following script where I will use the double ampersand &lt;span style="font-weight:bold"&gt;&amp;amp;&amp;amp; &lt;/span&gt;and the double pipe &lt;span style="font-weight:bold"&gt;||&lt;/span&gt;:&lt;br&gt;&lt;br&gt;I want to create a script that will ping all workstations and give me a file on non-pingable addresses and and a file on pingable addresses…&lt;br&gt;&lt;br&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;For /f %a IN (computerlist.txt) Do @(ping -n 1 %a | find /i /c &amp;quot;Request timed out&amp;quot; &amp;gt;NUL &amp;amp;&amp;amp; echo %a: No Reply &amp;amp;&amp;amp; echo %a &amp;gt;&amp;gt; noreply.txt) || (ping -n 1 %a | find /i /n &amp;quot;Reply from&amp;quot; &amp;gt;NUL &amp;amp;&amp;amp; echo %a: Pingable &amp;amp;&amp;amp; echo %a &amp;gt;&amp;gt; pingable.txt)&lt;/span&gt; &lt;br&gt;&lt;br&gt;The above script will ping a list of workstations and create two lists, one of computers that did not respond to a ping (noreply.txt) and another that did respond to a ping (pingable.txt) while giving us some output on the screen as well.&lt;br&gt;&lt;br&gt;To ping a subnet, we can change the &lt;span style="font-weight:bold"&gt;For..In..Do&lt;/span&gt; loop to process a number set:&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/font&gt;&lt;font size=2&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;For
/l %a IN (1,1,255) Do @(ping -n 1 192.168.1.%a | find /i /c &amp;quot;Request
timed out&amp;quot; &amp;gt;NUL &amp;amp;&amp;amp; echo %a: No Reply &amp;amp;&amp;amp; echo %a
&amp;gt;&amp;gt; noreply.txt) || (ping -n 1 192.168.1.%a | find /i /n &amp;quot;Reply from&amp;quot;
&amp;gt;NUL &amp;amp;&amp;amp; echo %a: Pingable &amp;amp;&amp;amp; echo %a &amp;gt;&amp;gt;
pingable.txt)&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=2&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;br&gt;The above script would ping 192.168.1.1 through 192.168.1.255 and produce the same output files as above.&lt;br&gt;&lt;br&gt;The examples above are just to show the possibilities of using compund command symbols and may need to be edited for your specific environment and/or use.&lt;br&gt;&lt;br&gt;Gill&lt;/span&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;/span&gt;&lt;/font&gt;&lt;br&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=226155696666371674&amp;page=RSS%3a+Compund+command+symbols&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gilliath.spaces.live.com&amp;amp;GT1=Gilliath"&gt;</description><comments>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!119.entry#comment</comments><guid isPermaLink="true">http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!119.entry</guid><pubDate>Sat, 12 Aug 2006 18:51:55 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://Gilliath.spaces.live.com/blog/cns!32377686BBAE65A!119/comments/feed.rss</wfw:commentRss><wfw:comment>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!119.entry#comment</wfw:comment><dcterms:modified>2006-08-12T18:51:55Z</dcterms:modified></item></channel></rss>