Friday, July 13, 2007

We all love Ping

really useful XP batch scripting resource.

I used it to put together the following.
for /L %%V in (1,1,255) do ping -n 1 -a  193.168.1.%%V >> c:\pingedMachines.txt

This pings every device in a given subdomain resolving the names as it does.
there are tools out there that will do this for you, but this will work on a vanilla XP machine. You could even parse the output to prettify it but if you need something
rough and ready this'll do.

really useful if that router isn't at the ip address you thought it was.

Ant tips

Depending on how your ant build is set up you may end up changing some properties more often than others. More often than not properties are fairly static so placing
them in a properties file is sufficent for most needs.

There are,however situations where you will change other properties more frequently,
say for example if you have a flag that controls whether you are performing a full build
(pull everything from cvs and start from scratch) or a partial build (where you
want to rebuild from source you've already pulled down with some minor change).

This is two tips relating to these frequently changing properties.

First of all to override a property in your properties file, set it on the command line
using the -D parameter.

 ant -DfullBuildPropertyName=true TaskName

This works because properties , once loaded in ant are immutable, so even if in your script
you load a properties file containing 'fullBuildPropertyName=false' it is ignored.

Secondly you can prompt the user to input a value when your script starts and set a property
based on that using the ant input tag.

for example:

<target name="getJavadocInput" unless="generate.javadoc" >
message="Do you want to generate javadoc"
<condition property="generate.javadoc">
<equals arg1="y" arg2="${input.javadoc}"/>

In this case the unless attribute in our target will not run if the property is already set
(in a property file or from the command line as per the last tip,
this means that we can run the script without user input if required (say for example
a scheduled build).

(incidentally the condition is not necessary, its simply a way of setting an 'empty'
property based on the value of the user entered property.)