<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Batch on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/batch/</link><description>
Recent content about Batch from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/tags/batch/feed.xml" rel="self" type="application/rss+xml"/><item><title>Cygwin BASH function to open the latest version of a document</title><link>https://it.knightnet.org.uk/2009/07/cygwin-bash-function-to-open-the-latest-version-of-a-document.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/07/cygwin-bash-function-to-open-the-latest-version-of-a-document.html</guid><pubDate>Wed, 15 Jul 2009 21:43:50 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/07/cygwin-bash-function-to-open-the-latest-version-of-a-document.html</guid><description><div/><div>&lt;p>One handy function I’ve added to .bashrc (so it is always available) under Cygwin (the LINUX command environment for Windows) works out the current working version of a document. It assumes that you keep copies that have a version number or date in the file name that will sort correctly.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>You can use it with an alias like this:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>If you name your documents sensibly such as “a-document-2009-07-20.doc” or “a-document-v01.01.doc”, then the latest version of the file will be opened in the default application&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;p>&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Technorati&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->BASH&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Diigo Tag Search&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->BASH&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/bash">BASH</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/cygwin">Cygwin</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category></item><item><title>Speeding up Cygwin</title><link>https://it.knightnet.org.uk/2009/07/speeding-up-cygwin.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/07/speeding-up-cygwin.html</guid><pubDate>Wed, 15 Jul 2009 14:54:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/07/speeding-up-cygwin.html</guid><description><div/><div>&lt;p>Yesterday I mentioned my success with Cygwin.
One issue I did have though was with the speed of startup. It was taking 15-20 seconds to start a BASH shell.
It turns out that this was a PATH issue. I went through my Windows PATH and cleared out the clutter. Now it takes just around 3-4 seconds for a full BASH login and less still for just running a script.
I now find myself using the BASH shell for all sorts of things and I’ve set up a number of alias’s to switch to folders I’m using a lot and to open common documents.
One handy function I’ve added to .bashrc (so it is always available) works out the current working version of a document. It assumes that you keep copies that have a version number or date in the file name that will sort correctly.
You can find the code on my &lt;!-- raw HTML omitted -->development blog&lt;!-- raw HTML omitted -->.
Here are a few more alias’s I use:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/configuration">Configuration</category><category domain="https://it.knightnet.org.uk/tags/cygwin">Cygwin</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category></item><item><title>Windows command prompt vs PowerShell vs Cygwin for remote backup scripts</title><link>https://it.knightnet.org.uk/2009/07/windows-command-prompt-vs-powershell-vs-cygwin-for-remote-backup-scripts.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/07/windows-command-prompt-vs-powershell-vs-cygwin-for-remote-backup-scripts.html</guid><pubDate>Mon, 13 Jul 2009 14:44:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/07/windows-command-prompt-vs-powershell-vs-cygwin-for-remote-backup-scripts.html</guid><description><div/><div>&lt;p>I’ve been struggling with trying to get a new backup routine working for my Laptop.
I should point out that I have several complex requirements for backup so my needs are probably not average.
However, it really shouldn’t be this hard!
I need to use a combination of BZR (Bazaar) for document version control and RSYNC (for files that don’t need version control and for those folders that might contain files too big for version control systems – around 1/3 to 1/2 available memory).
All of the backups need to happen over a secure link since I am often outside of my home network – indeed quite often behind locked-down enterprise firewalls but that’s a story for another time. So I use SSH (Secure SHell) to manage the secure connection and transmission. Thankfully both BZR and RSYNC can both use SSH as a transport.
I don’t want to have to enter my remote system password loads of times though and this is where things started to get annoying. Using the Windows native versions of BZR, RSYNC and SSH I could not get a single shared password to work no matter what I tried.
I also had some problems trying to control the output from the various tools and use it to further control what happens next – for example getting an IP address and working out whether I am on a network and where that network is.
I tried to do this with a Windows command script first but even with the Windows 7 extensions it really is far to hard to get anything useful done and when I found myself turning to more and more utilities to help I thought “enough is enough”.
At that point I happened to be reading an article on Windows PowerShell, the .NET scripting host so I thought I’d give it another go (having tried it before). I soon found that, although powerful for controlling the WMI interface, it is desperately convoluted and annoying for general use.
So, realising that most of the tools I wanted to use have their roots in the UNIX world, it would make sense to try out the latest version of Cygwin. This has really come on a long way since it’s early days and is far more mature. It is also very much lighter in weight than the Microsoft provided UNIX services for Windows or whatever they are currently calling it. The Microsoft provided tools load perhaps a dozen services into memory permanently though they are rarely required. Cygwin only uses memory when it needs to.
After converting my backup script from Windows batch to a BASH script under Cygwin, I soon had everything working as I wanted it – including the seemingly intractable problem of the shared passwords, now using KEYCHAIN to manage the SSH-AGENT and keys. So now I only need to supply a password once, it is held reasonably securely in memory and used by SSH as and when required. I only need to enter it once per reboot.
The full script not only backs things up, it also auto-commits changes to BZR and changes network settings to match my current location and proxy server requirements. The later is not yet converted from batch as I don’t need it just at the moment.
Let me know if you are interested in a copy of the script and I’ll upload it somewhere.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/software">Software</category><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/backup">Backup</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/cygwin">Cygwin</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category><category domain="https://it.knightnet.org.uk/tags/win7">Win7</category></item><item><title>How-to show a Message of the Day (MOTD) at the Windows Command Prompt</title><link>https://it.knightnet.org.uk/2009/05/how-to-show-a-message-of-the-day-motd-at-the-windows-command-prompt.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/05/how-to-show-a-message-of-the-day-motd-at-the-windows-command-prompt.html</guid><pubDate>Tue, 12 May 2009 22:33:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/05/how-to-show-a-message-of-the-day-motd-at-the-windows-command-prompt.html</guid><description><div/><div>&lt;p>One of the features available under UNIX is the Message of the Day (MOTD). This is run every time you start a command prompt and displays the content of a file. In addition, the UNIX shells allow all sorts of stuff to be run and configured every time you start a new prompt using the .profile and .bashrc command files.&lt;/p>
&lt;p>Windows users don&amp;rsquo;t generally expect that kind of flexibility from their command prompts. However, Windows does indeed support the use of an &lt;code>autorun&lt;/code> into which you can shoe-horn any command you like.&lt;/p>
&lt;p>So for my standard setup, I make the shell autorun run a &lt;code>.profile.cmd&lt;/code> file that sits in the &lt;code>%USERPROFILE%&lt;/code> folder. From that file, I can run anything I like.&lt;/p>
&lt;p>To set up a shell autorun, you have to edit the registry so the usual warnings to be careful and back things up apply.&lt;/p>
&lt;p>There are two locations you can set, one for the machine as a whole and one for the logged-in user.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-ini" data-lang="ini">&lt;span class="line">&lt;span class="cl">&lt;span class="na">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If you want to set an autorun for another user, you need to go down &lt;code>HKEY_USERS&lt;/code> and find the appropriate one. It is really easier just to log in!&lt;/p>
&lt;p>In one or both of those locations, add a new &amp;ldquo;String Value&amp;rdquo; (&lt;code>REG_SZ&lt;/code>) called &lt;code>AutoRun&lt;/code> with the value:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cmd" data-lang="cmd">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">%USERPROFILE%&lt;/span>\.profile.cmd
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now create that file and put in a message such as:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cmd" data-lang="cmd">&lt;span class="line">&lt;span class="cl">&lt;span class="p">@&lt;/span>&lt;span class="k">echo&lt;/span> &lt;span class="s2">&amp;#34;Hello and welcome to my command prompt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Save the file and open a new shell and you should see the message just after the Microsoft copyright.&lt;/p>
&lt;p>This should work on all versions of Windows at least from XP onwards.&lt;/p>
&lt;p>If you want to add this to a batch file to set up new machines, here is the command you need:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cmd" data-lang="cmd">&lt;span class="line">&lt;span class="cl">reg.exe ADD &lt;span class="s2">&amp;#34;HKLM\SOFTWARE\Microsoft\Command Processor&amp;#34;&lt;/span> /v AutoRun /t REG_SZ /d &lt;span class="se">^%&lt;/span>USERPROFILE&lt;span class="se">^%&lt;/span>\.profile.cmd /f
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>(Note that the above needs to go on a single line)&lt;/p>
&lt;hr>
&lt;h2 id="updates">Updates&lt;/h2>
&lt;ul>
&lt;li>2018-04-22 - Tidy formatting, reformat for Hugo output.&lt;/li>
&lt;/ul>
&lt;!-- raw HTML omitted -->
&lt;p>&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Technorati&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Diigo Tag Search&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/configuration">Configuration</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category><category domain="https://it.knightnet.org.uk/tags/vista">Vista</category><category domain="https://it.knightnet.org.uk/tags/win7">Win7</category></item><item><title>Keeping Control: File and Folder Links for Windows Users</title><link>https://it.knightnet.org.uk/2009/04/keeping-control-file-and-folder-links-for-windows-users.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/04/keeping-control-file-and-folder-links-for-windows-users.html</guid><pubDate>Mon, 27 Apr 2009 21:12:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/04/keeping-control-file-and-folder-links-for-windows-users.html</guid><description><div/><div>&lt;p>A good backup strategy for any computer involves keeping control of where stuff is stored. The fewer locations that contain files that change, the fewer locations have to be maintained.
UNIX users have always had the ability to keep things wherever they wanted and then to LINK that information into the required location. Basically, links create a link or tunnel between one file or folder and another. Most of the time, you will not notice that you’ve entered a tunnel and you are not interested really.
Windows users, however, have always been the poor cousins here. Stuck as we were in &lt;!-- raw HTML omitted -->FAT&lt;!-- raw HTML omitted -->land, we had no access to fancy features such as links. So Microsoft in their inimitable fashion created a poor-man’s link – the Windows Shell Shortcut – so that the Windows GUI had some minimal capability (really only for menu’s and Windows Explorer).
Windows 2000 improved on this by introducing “Reparse Points” one form of which is the “&lt;!-- raw HTML omitted -->Junction&lt;!-- raw HTML omitted -->“. This is an extension to NTFS that allows folders to be joined (linked) to another location in the local volume space. Making junctions is not an obvious process, you can do it from the disk manager and there is a tool in the Windows 2000 server resource kit called &lt;code>linkd&lt;/code>. The POSIX tools included in the resource kit contain the UNIX command &lt;code>ln&lt;/code> which can also create junction points and hard links; &lt;code>fsutil&lt;/code> in XP can also. There are some third party tools too.
It’s odd because I seem to remember that OS/2 had some kind of linking feature.
Anyway, links of the UNIX type are a massively useful feature that has finally (with Vista, Windows 2008 and beyond) made it fully to NTFS and Windows.
Vista, Windows 2008 and Windows 7 all have a command line tool called &lt;code>mklink&lt;/code>. This can be used like the Unix &lt;code>ln&lt;/code> command to create both hard links (which must be on the same volume) and soft links. Soft links under Windows can, in fact, span across SMB network drives as well.
You might also like to look at another free tool called “&lt;!-- raw HTML omitted -->Link Shell Extension&lt;!-- raw HTML omitted -->” by Hermann Schinagl. This integrates into Windows Explorer, the web site also has a more complete explanation of the history of links in Windows. LSE does a number of clever things and is well worth a look. Hermann also has a “dupmerge” tool on his web site that will replace duplicated files with hard links.
So now, if we want to tweak the HOSTS file for example (c:\windows\system32\drivers\etc\hosts), we don’t need to leave in place since that would mean that we would need an extra backup routine. Instead, copy it to somewhere that already gets backed up. Delete the original file and then from the command line:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Now you can edit the hosts file from either location, there is only one file (in &lt;code>%USERPROFILE%\BACKUPS&lt;/code>). The difference being that even if you delete the file from its normal location, it will still exist in the “real” location. If you delete it from its “real” place in &lt;code>BACKUPS&lt;/code> of course, the link will be broken and wont work.
To link a complete folder, it is the same command with a &lt;code>/D&lt;/code> parameter added. For example, I keep a folder of command line utilities such as &lt;code>ls&lt;/code>, &lt;code>ssh&lt;/code> and &lt;code>rsync&lt;/code> in a folder on a USB pen drive. I sync that folder to the &lt;code>BACKUPS&lt;/code> location on my hard drive for convenience but I need the folder in my &lt;code>PATH&lt;/code> otherwise its hard to execute the utilities. I don’t want a really long path, it’s bad enough already, so I link the folder to &lt;code>c:\cmd&lt;/code> with the following:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Now I add c:\cmd to the path and the utilities seem to be in both places.
I’ve said in other posts that I like to reinstall Windows now and again but it can be a pain to restore all of the document files. Similarly, if you keep multiple operating systems on your hard drive, how do you keep your documents sorted? One way is to put all documents, videos, music, etc. onto a separate partition. Now, instead of going mad with the Windows registry trying to relocate your normal documents folders to another drive. Simply delete the normal documents folder – &lt;code>%USERPROFILE%\Documents\&lt;/code> under Windows 7 and relink it to the appropriate folder on the other drive as so:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Put this in a script that you run when you reinstall Windows and its easy and quick.
One final note. You may find a few pieces of software that cannot cope with links. Certainly &lt;!-- raw HTML omitted -->Subversion&lt;!-- raw HTML omitted --> cannot though &lt;!-- raw HTML omitted -->Bazaar&lt;!-- raw HTML omitted --> can. Windows Explorer seems OK though as do utilities such as &lt;!-- raw HTML omitted -->RSYNC&lt;!-- raw HTML omitted -->.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;p>&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Technorati&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Backup&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Diigo Tag Search&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Backup&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/backup">Backup</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/configuration">Configuration</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category><category domain="https://it.knightnet.org.uk/tags/vista">Vista</category><category domain="https://it.knightnet.org.uk/tags/win7">Win7</category></item><item><title>Changing system environment variables from the Windows command line</title><link>https://it.knightnet.org.uk/2009/03/changing-system-environment-variables-from-the-windows-command-line.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/03/changing-system-environment-variables-from-the-windows-command-line.html</guid><pubDate>Tue, 24 Mar 2009 11:21:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/03/changing-system-environment-variables-from-the-windows-command-line.html</guid><description><div/><div>&lt;p>There are several ways to change global or user environment variables manually in Windows. Most are well known so I wont repeat them here (e.g. in Vista or Windows 7, Control Panel/User Accounts, Change my environment variables).
However, sometimes you want to do this from a command (aka script or batch) file. This is not as straightforwards as it might seem. That’s because if you simply set the variable – e.g. &lt;code>set FRED=JimBob&lt;/code> – it is only set while you are in that command file. Once the script has finished, the variable will no longer be set.
There are a number of examples of setting system or user environment variables available if you do a Google search but most of them are incomplete – they do not immediately make the new value available to all applications (and particularly to new command shells).
To make sure that the new value is available system-wide, you have to tell Windows to refresh the environment variable list and the easiest way to ensure this happens is to change the variable from a [Windows Scripting Host][1] ([WSH][2]) script.
Here is an example script to do this. Save this file as something like &lt;code>set-env.vbs&lt;/code> somewhere convenient.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Note that in Vista or above, you will need to run the command file with elevated privileges for this to work. The normal command prompt gets this automatically but if you want to run the file from Windows Explorer, you will need to create a shortcut and change the settings.
You can now use this in your batch command scripts, for example:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Technorati&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->VBS&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Diigo Tag Search&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Configuration&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Scripting&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->VBS&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/configuration">Configuration</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category><category domain="https://it.knightnet.org.uk/tags/vbs">VBS</category></item><item><title>How to get and use your local IP address in a Windows 7 (and Vista) batch command file</title><link>https://it.knightnet.org.uk/2009/03/how-to-get-and-use-your-local-ip-address-in-a-windows-7-and-vista-batch-command-file.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2009/03/how-to-get-and-use-your-local-ip-address-in-a-windows-7-and-vista-batch-command-file.html</guid><pubDate>Fri, 20 Mar 2009 14:11:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2009/03/how-to-get-and-use-your-local-ip-address-in-a-windows-7-and-vista-batch-command-file.html</guid><description><div/><div>&lt;p>If, like me, you spend a lot of time on a variety of customer sites, you will probably be familiar with the issues around swapping networks.
I’ve already blogged about the &lt;!-- raw HTML omitted -->problems with Windows 7, Vista and Firefox proxy settings&lt;!-- raw HTML omitted --> and I will do some more articles on getting on with problematic proxies later. However, I wanted to let people know how to get hold of your IP address from within a batch (command) file.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Note the space after the : on line 3. The &lt;code>FOR&lt;/code> command used twice here splits the text output from what is in the &lt;code>()&lt;/code> after the “&lt;code>in&lt;/code>” using the defined delimiters (“&lt;code>:&lt;/code>” and space in the 1&lt;!-- raw HTML omitted -->st&lt;!-- raw HTML omitted --> case, “.” in the 2&lt;!-- raw HTML omitted -->nd&lt;!-- raw HTML omitted -->). In the first &lt;code>FOR&lt;/code> statement, we take element number 13 only, it ends up in variable &lt;code>%%i&lt;/code>. In the second case, we take elements number 1 to 4, they go into variables &lt;code>%%a&lt;/code>, &lt;code>%%b&lt;/code>, &lt;code>%%c&lt;/code>, &lt;code>%%d&lt;/code>.
Now you have not only the full address but also the componants so if you wanted to check whether you were in a particular class C network, you could do something like:&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>That would check if your local IP address is between 10.97.100.1 and 10.97.199.254
&lt;!-- raw HTML omitted -->Note&lt;!-- raw HTML omitted --> that I’ve used the enhanced &lt;code>FOR&lt;/code> statement – the “&lt;code>usebakq&lt;/code>” makes the FOR statement more like a UNIX type one where commands are enclosed in back-quotes (`). This certainly works for Windows 7 and should, I think, work for Vista. Prior to Vista, you would need to do things differently anyway. At the very least you would have to search for “IP Address” in the &lt;code>FIND&lt;/code> statement as &lt;code>IPCONFIG&lt;/code> didn’t include IPv6 information.
Now that you have everything in place, you can control the proxy settings for each application that needs access out of the local network. I’ll blog about that another time.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;p>&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Technorati&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted --> &lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->Diigo Tag Search&lt;!-- raw HTML omitted --> : &lt;!-- raw HTML omitted -->Batch&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Vista&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Win7&lt;!-- raw HTML omitted -->, &lt;!-- raw HTML omitted -->Windows&lt;!-- raw HTML omitted -->&lt;!-- raw HTML omitted -->&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/windows">Windows</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/vista">Vista</category><category domain="https://it.knightnet.org.uk/tags/win7">Win7</category></item><item><title>Shell script to Back up critical files (using RSYNC)</title><link>https://it.knightnet.org.uk/2008/08/shell-script-to-back-up-critical-files-using-rsync.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2008/08/shell-script-to-back-up-critical-files-using-rsync.html</guid><pubDate>Thu, 14 Aug 2008 01:57:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2008/08/shell-script-to-back-up-critical-files-using-rsync.html</guid><description><div/><div>&lt;p>Following up from my article on backing up USB drives, this recipe backs up the critical files on my desktop to remote storage (a NAS device on my network). Note that PC2 is the desktop to be backed up, SLUG1 (192.168.1.2) is the NAS device and USER1 is the user id doing the backup.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>I have a similar script that runs on the NAS device which backs key files on that to a remote hosting service on a different continent! That way, I don’t have to worry about the house burning down or being burgled.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/linux">Linux</category><category domain="https://it.knightnet.org.uk/tags/backup">Backup</category><category domain="https://it.knightnet.org.uk/tags/bash">BASH</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category></item><item><title>Automatically Backing up a USB Drive with RSYNC (KDE)</title><link>https://it.knightnet.org.uk/2008/08/automatically-backing-up-a-usb-drive-with-rsync-kde.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2008/08/automatically-backing-up-a-usb-drive-with-rsync-kde.html</guid><pubDate>Thu, 14 Aug 2008 01:22:00 +0000</pubDate><guid>https://it.knightnet.org.uk/2008/08/automatically-backing-up-a-usb-drive-with-rsync-kde.html</guid><description><div/><div>&lt;p>USB Drives of all kinds need to be backed up and the best backup is an automatic one (it’s the only way to make sure that it gets done!).&lt;/p>
&lt;p>So here is one recipe for doing just that using RSYNC and some BASH scripting magic.&lt;/p>
&lt;p>I’ve split this into two files. You don’t have to do this of course and one may well be better for you. I used two because I can run the second one manually as well. Put everything in autorun.sh if you want to backup each drive individually, however, note that KDE produces an annoying extra dialog (a security warning) asking if you really want to run the autorun.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>autorun.sh&lt;/p>
&lt;p>This resides in the root of the USB drive and is executed automatically by KDE when the drive is detected (though not if the drive is attached when booting)&lt;/p>
&lt;/li>
&lt;li>
&lt;p>usb-backup-manual.sh&lt;/p>
&lt;p>This is a bit of a nasty hack, I have manually configured a list of drives that might be attached so that I can back them all up together. Not elegant but it works for me.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h4 id="autorunsh">autorun.sh&lt;/h4>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Note the use of KDialog to provide a minimal GUI. In the second file, KDialog produces a progress bar.&lt;/p>
&lt;p>Also note the RSYNC parameters. These are always painful to get to grips with so it is nice to have an example to work from. In this case I am backing up so I am making sure that the backup is an exact copy of the original (as opposed to synchronising which would allow changes to happen on either side).&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/linux">Linux</category><category domain="https://it.knightnet.org.uk/tags/backup">Backup</category><category domain="https://it.knightnet.org.uk/tags/bash">BASH</category><category domain="https://it.knightnet.org.uk/tags/batch">Batch</category><category domain="https://it.knightnet.org.uk/tags/scripting">Scripting</category><category domain="https://it.knightnet.org.uk/tags/usb">USB</category></item></channel></rss>