<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>ITauthor &#187; Shell scripts</title>
	<atom:link href="http://www.itauthor.com/category/shell-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.itauthor.com</link>
	<description>Stuff about technical writing and software</description>
	<lastBuildDate>Sat, 07 Jan 2012 12:34:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<!-- podcast_generator="Blubrry PowerPress/2.0.4" -->
	<itunes:summary>Talking about technical writing, software and technology in general. The ITauthor Podcast is an advert-free, irregularly published show by technical writers for technical writers or anyone interested in software documentation or IT generally.</itunes:summary>
	<itunes:author>Alistair Christie - ITauthor.com</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.itauthor.com/images/ITauthor-PhotoLogo-300px.jpg" />
	<itunes:owner>
		<itunes:name>Alistair Christie - ITauthor.com</itunes:name>
		<itunes:email>comments@itauthor.com</itunes:email>
	</itunes:owner>
	<managingEditor>comments@itauthor.com (Alistair Christie - ITauthor.com)</managingEditor>
	<copyright>2006-2009</copyright>
	<itunes:subtitle>Talking about technical writing, software and technology in general.</itunes:subtitle>
	<itunes:keywords>itauthor, alistair christie, technology, writing, documentation</itunes:keywords>
	<image>
		<title>ITauthor &#187; Shell scripts</title>
		<url>http://www.itauthor.com/images/ITauthor-PhotoLogo-144px.jpg</url>
		<link>http://www.itauthor.com/category/shell-scripts/</link>
	</image>
	<itunes:category text="Technology">
		<itunes:category text="Software How-To" />
		<itunes:category text="Tech News" />
		<itunes:category text="Podcasting" />
	</itunes:category>
		<item>
		<title>Scan for available IP addresses</title>
		<link>http://www.itauthor.com/2011/08/28/scan-for-available-ip-addresses/</link>
		<comments>http://www.itauthor.com/2011/08/28/scan-for-available-ip-addresses/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 09:33:15 +0000</pubDate>
		<dc:creator>ac</dc:creator>
				<category><![CDATA[Shell scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.itauthor.com/2011/08/28/scan-for-available-ip-addresses/</guid>
		<description><![CDATA[How do you connect to a device on your local network when you know a valid user name and password but the machine: Is not in your DNS system so you can’t get to it using a host name Has a static IP address that’s assigned on the machine itself - but you don’t know [...]]]></description>
			<content:encoded><![CDATA[<p>How do you connect to a device on your local network when you know a valid user name and password but the machine:</p>
<ul>
<li>Is not in your DNS system so you can’t get to it using a host name </li>
<li>Has a static IP address that’s assigned on the machine itself - but you don’t know what the address is </li>
</ul>
<p>The answer is you need to use trial and error to find and IP address that asks you for a user name and password and when you plug in the user name and password you know are valid you get a connection.</p>
<p>This is a whole lot quicker if the machine accepts <strong>ping</strong> requests (which are basically little “hello, anyone there?” messages fired at a computer, to which the machine answers “yup,” if it wants to, and your computer tells you how long it took to get a response).</p>
<p>If you don’t already have a <a title="See section below" href="#scanners">network scanner*</a> installed, here’s a little shell script you can run from a Windows command prompt. Fire up the command console (<strong>cmd.exe</strong>) and enter this (changing the bits in red to suit yourself):</p>
<p> <code>SET fl=<span style="color: red">c:\Alistair\ipaddresses.txt</span> &amp; ECHO =================================================== &gt;&gt; %fl% &amp; ECHO.%date% %time% &gt;&gt; %fl% &amp; FOR /L %i IN (<span style="color: red">0</span>,1,<span style="color: red">255</span>) DO ping -n 1 <span style="color: red">192.168.0</span>.%i | FIND /i &quot;Reply&quot; | FIND /i /v &quot;unreachable&quot; &gt;&gt; %fl%</code>
<p>In the above:</p>
<ul>
<li><strong>c:\Alistair\ipaddresses.txt</strong> is the path to the log file where I want to write the IP addresses </li>
<li><strong>(0,1,255)</strong> means set the variable %i to 0 to start with, increment by 1 each time the FOR loop loops and stop after it reaches 255 </li>
<li><strong>192.168.0.%i</strong> is the IP address range (in this case this starts at 192.168.0.0 and ends at 192.168.0.255) </li>
</ul>
<p>The first FIND command finds all lines of output containing “Reply.” These get passed to the second FIND command which removes any lines that contain “unreachable.” The result is that ping output is only logged where the ping to an IP address was responded to.</p>
<p>The output in the log file looks something like this:</p>
<pre>===================================================
28/08/2011  9:22:24.26
Reply from 192.168.0.1: bytes=32 time=24ms TTL=64
Reply from 192.168.0.41: bytes=32 time=82ms TTL=64
Reply from 192.168.0.42: bytes=32 time&lt;1ms TTL=128</pre>
<p>A variation on the script is to look for host names for the IP addresses and log these, if found. This takes much longer to run but could be useful if you need to find out what machines on your network can be pinged with their host name: </p>
<p><code>SET fl=c:\Alistair\ipaddresses.txt &amp; ECHO =================================================== &gt;&gt; %fl% &amp; ECHO.%date% %time% &gt;&gt; %fl% &amp; FOR /L %i IN (0,1,255) DO ping -a -n 1 192.168.0.%i | FINDSTR /i &quot;Pinging.*\[ Reply&quot; | FIND /i /v &quot;unreachable&quot; &gt;&gt; %fl%</code> </p>
<p>Which produces output like this:</p>
<pre>===================================================
28/08/2011  9:22:24.26
Reply from 192.168.0.1: bytes=32 time=24ms TTL=64
Reply from 192.168.0.41: bytes=32 time=82ms TTL=64
Pinging rolumus [192.168.0.42] with 32 bytes of data:
Reply from 192.168.0.42: bytes=32 time&lt;1ms TTL=128</pre>
<p>In this example, just one of the machines could be reached by a host name: romulus.</p>
<h4>Turn it into a batch file</h4>
<p>If, for some reason, you can see yourself needing to use this script now and again you might want to save it as a batch file that you can run simply by double-clicking the file in Windows Explorer. Here’s an example of a batch file that runs the second (slower) of the scripts:</p>
<p><code>@ECHO OFF<br class="workaround" />REM Created by Alistair 28/8/2011<br class="workaround" />REM See blog post on this: http://www.itauthor.com/2011/08/28/scan-for-available-ip-addresses/<br class="workaround" />REM For more batch file commands, see: http://ss64.com/nt/<br class="workaround" />SET fl=c:\Alistair\ipaddresses.txt<br class="workaround" />ECHO Scan IP addresses for ones that accept a ping request.<br class="workaround" />ECHO The output from this batch file is logged in %fl%<br class="workaround" />ECHO Scanning ...<br class="workaround" />ECHO =================================================== &gt;&gt; %fl% &amp; ECHO.%date% %time% &gt;&gt; %fl% &amp; FOR /L %%i IN (0,1,255) DO ping -a -n 1 192.168.0.%%i | FINDSTR /i &quot;Pinging.*\[ Reply&quot; | FIND /i /v &quot;unreachable&quot; &gt;&gt; %fl% &amp; ECHO 192.168.0.%%i<br class="workaround" />ECHO Scan completed. See log file (%fl%) for results. </code></p>
<p>Just save this as a file with a <strong>.bat</strong> file name extension (e.g. <strong>checkIPaddresses.bat</strong>) in a location that doesn’t require Administrator privileges. For example, if you want to run it from your desktop don’t save the batch file to your desktop, save it somewhere like <strong>C:\YourStuff\batchFiles\</strong>, then create a shortcut and put the shortcut on your desktop.</p>
<h4><a name="scanners"></a>Network scanners</h4>
<p>Be very careful if you’re considering installing a network scanner. There are a lot of port and IP addresses scanners out there and a lot of them are malware. They might do the job OK but they also come with viruses, so watch out. There are infected/corrupted versions of reputable scanners, so don’t assume something is OK just because you’ve read good stuff about it, unless you are completely confident you’re getting the kosher version of it.</p>
<h4>More information</h4>
<p>A good source of information about Windows shell commands is: <a title="http://ss64.com/nt/" href="http://ss64.com/nt/">http://ss64.com/nt/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.itauthor.com/2011/08/28/scan-for-available-ip-addresses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Displaying the host name of a UNIX server on login</title>
		<link>http://www.itauthor.com/2007/09/27/displaying-the-host-name-of-a-unix-server-on-login/</link>
		<comments>http://www.itauthor.com/2007/09/27/displaying-the-host-name-of-a-unix-server-on-login/#comments</comments>
		<pubDate>Thu, 27 Sep 2007 19:31:33 +0000</pubDate>
		<dc:creator>ac</dc:creator>
				<category><![CDATA[Shell scripts]]></category>
		<category><![CDATA[UNIX/Linux]]></category>
		<category><![CDATA[View all]]></category>

		<guid isPermaLink="false">http://www.itauthor.com/wordpress/2007/09/27/displaying-the-host-name-of-a-unix-server-on-login/</guid>
		<description><![CDATA[To show the host name of a server when you log in to it. Add the following at the end of your shell startup file (e.g. .bashrc or .cshrc in your home directory): perl banner.pl Then create the following Perl script in your home directory and call it banner.pl. # Perl script for printing banner [...]]]></description>
			<content:encoded><![CDATA[<p>To show the host name of a server when you log in to it. Add the following at the end of your shell startup file (e.g. <strong>.bashrc</strong> or <strong>.cshrc</strong> in your home directory):</p>
<p><font size="2" face="Courier New">perl banner.pl </font></p>
<p>Then create the following Perl script in your home directory and call it <strong>banner.pl</strong>.</p>
<p><code><font size="2" face="Courier New"># Perl script for printing banner showing name of local host </font></code><code><font size="2" face="Courier New">use Text::Banner;<br />
$a = Text::Banner-&gt;new;<br />
$a-&gt;set(`hostname`);<br />
$a-&gt;size(1);<br />
$a-&gt;fill('');<br />
$a-&gt;rotate('h'); </font></code><code><font size="2" face="Courier New">print "\n";<br />
drawlines();<br />
print $a-&gt;get;<br />
drawlines();<br />
print "\n";<br />
print "\n"; </font></code><code><font size="2" face="cour"><font face="Courier New">sub drawlines() {<br />
<code><font size="2" face="cour"></font></code>&nbsp; &nbsp; for ($loop=1; $loop&lt;4; $loop++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; for ($n=1; $n&lt;60; $n++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print "=";<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; print "\n";<br />
&nbsp; &nbsp; }<br />
}</font> </font></p>
<p></code><code>Finally, install the Text::Banner perl module&nbsp; from CPAN. Note: if you don't want to (or can't) install the Perl module in the normal way on the server, you can&nbsp; download the zip file from the CPAN Web site (<a href="http://search.cpan.org/~lory/Text-Banner-1.00/Banner.pm" title="http://search.cpan.org/~lory/Text-Banner-1.00/Banner.pm">http://search.cpan.org/~lory/Text-Banner-1.00/Banner.pm</a>), <strong>gunzip</strong> and <strong>tar xvf</strong> it&nbsp; in your home directory and then change the 'use' statement to:</code><code><font size="2" face="Courier New">use Banner::Banner; </font></p>
<p>Now, when you log in to the server you get something like this (in this case the server is called pegasus):</p>
<p></code><img border="0" width="488" src="http://www.itauthor.com/wp-content/uploads/2007/09/pegasusbanner.png" alt="pegasusbanner" height="255" style="border: 0px" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.itauthor.com/2007/09/27/displaying-the-host-name-of-a-unix-server-on-login/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using a shell script to replace text in multiple files</title>
		<link>http://www.itauthor.com/2005/01/22/using-a-shell-script-to-replace-text-in-multiple-files/</link>
		<comments>http://www.itauthor.com/2005/01/22/using-a-shell-script-to-replace-text-in-multiple-files/#comments</comments>
		<pubDate>Sat, 22 Jan 2005 11:03:42 +0000</pubDate>
		<dc:creator>alistair at home</dc:creator>
				<category><![CDATA[FrameMaker]]></category>
		<category><![CDATA[Shell scripts]]></category>

		<guid isPermaLink="false">http://www.itauthor.com/wordpress/?p=105</guid>
		<description><![CDATA[The problem I usually work at the office, but occasionally work from home. At the office I can browse to any networked server in Windows (e.g. in Windows Explorer) by entering an address like \\networkedserver. When I'm working from home, I log on to my work network via an SSH session. This works fine, but [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong><br />
I usually work at the office, but occasionally work from home. At the office I can browse to any networked server in Windows (e.g. in Windows Explorer) by entering an address like \\networkedserver. When I'm working from home, I log on to my work network via an SSH session. This works fine, but one drawback is that, because it's not a VPN session my home PC is not part of the work network, so although I can access machines from a command line, using SSH, or upload/download files using WinSCP, addresses like \\networkedserver don't work because (unless "networkedserver" happens to be one of my own machines on my own home network). </p>
<p><strong>How this affects my work</strong><br />
The only hassle this causes is when I work on structured FrameMaker files from home. I need to copy the source XML files from the server at work to my own machine (using WinSCP) and then modify them the path to the DTD, using a text editor. Once I've finished working on them in FrameMaker and I want to copy them back to the work server, I need to change the DTD reference back to one that works on my work network. </p>
<p>For example, at work the FrameMaker XML files I work with reference a DTD called mxDocBook.dtd. Let's say the path to this is //networkserver/mxDocBook/mxDocBook-DTD/mxDocBook.dtd. So the start of each XML file looks like this:</p>
<p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;!DOCTYPE chapter SYSTEM "//networkserver/mxDocBook/mxDocBook-DTD/mxDocBook.dtd" [<br />
...</p>
<p>If I tried to open this file in FrameMaker on a computer on my home network I'd get an error message, because FrameMaker wouldn't be able to find the DTD file. So I have to change the identifier to something like: </p>
<p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;!DOCTYPE chapter SYSTEM "file:///D:/work/mxDocBook/DTDfiles/mxDocBook.dtd" [<br />
...</p>
<p>Changing each file back and forwards could get very tedious, but there's a solution.</p>
<p><strong>The solution: the changedtd shell script</strong><br />
I wrote a shell script that you can use to automate this process. The script (called <strong>changedtd</strong>) contains variables called FINDTHIS, CHANGETOTHIS and FNAMEPATTERN. It looks for files in the current working directory that match the FNAMEPATTERN (typically *.xml) and performs a search/replace, searching for FINDTHIS and replacing it will CHANGETOTHIS.</p>
<p>If you want to use the script, copy it and edit the FINDTHIS and CHANGETHIS values to appropriate paths.</p>
<p>To run the shell script you obviously need a shell. I'd recommend installing Windows Services for UNIX 3.5 as the easiest way of getting a UNIX-like shell on a Windows machine.</p>
<p>You can download SFU 3.5 free of charge from:<br />
<a href="http://www.microsoft.com/windows/sfu/">www.microsoft.com/windows/sfu</a></p>
<p>Once you've got a shell, all you need to do is put the <strong>changedtd</strong> file in a directory that's in your PATH, and then, in a UNIX/SFU shell, browse to the directory containing the files you want to change and run the command: <strong>changedtd</strong> </p>
<p><strong>View/download the script</p>
<ul>
<li></strong><a href="http://www.itauthor.com/notes/archives/scripts/changedtd.html">View the script</a></li>
<li>To download the script, right-click <a href="http://www.itauthor.com/notes/downloadables/changedtd">this link</a> and choose <strong>Save Target As</strong> or <strong>Save Link As</strong>.</li>
</ul>
<p><strong>Notes</strong>:<br />
You might think it's a very long-winded script to do such a simple operation, but most of the verbosity of it comes from:<br />
a) The parsing of the command line arguments. This allows you to run the script on a directory other than the current working directory and to recurse into child directories (if you dare).<br />
b) The usage instructions, which you can read by running <strong>changedtd -h</strong>.<br />
c) You could of course very easily change this script to do a search/replace with any text you like on any type of file, just by changing the values of FINDTHIS, CHANGETOTHIS and FNAMEPATTERN.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itauthor.com/2005/01/22/using-a-shell-script-to-replace-text-in-multiple-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

