source: main/trunk/greenstone3/bin/script/IPv4.bat@ 30038

Last change on this file since 30038 was 30038, checked in by ak19, 9 years ago

Modified IPv4 scripts to take the parameter -format-for-tomcat-context if it needs to format the IPv4 address. If not passed this flag, it will return the IPv4 address unformatted. build.xml is now updated to pass this flag to the scripts.

  • Property svn:executable set to *
File size: 1.6 KB
RevLine 
[30036]1@echo off
[30038]2
3rem This script will echo the IPv4 of this windows machine. E.g. 100.200.300.45
4rem If passed -format-for-tomcat-context, it will echo the same with a pipe
5rem symbol up front and all the . escaped with a "\". E.g. "|100\.200\.300\.45"
6
[30036]7for /f "usebackq tokens=2 delims=:" %%a in (`ipconfig ^| find "IPv4"`) do (set result=%%a)
8
[30038]9:: To lop off the single extra space in front of IPv4 number, end with:
[30036]10::do (set result=%a& echo %result:~1%)
11:: Alternative: for /f "tokens=2 delims=:" %a in ('ipconfig ^| findstr /C:"IPv4 Address"') do echo %a
12:: still need to remove space up front for that too.
13
14:: removes extra space in front
15set result=%result:~1%
16
17:: The above produces the IPv4 number, e.g. 100.200.300.45
[30038]18
19
20rem Check if we're requested to format the IPv4 for the solr.xml tomcat context file
21if [%1]==[] goto done
22if not "%1"=="-format-for-tomcat-context" goto done
23
[30036]24:: Still need to replace . with \.
25:: http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute!OpenDocument&ExpandSection=3&BaseTarget=East&AutoFramed
26:: Syntax: %string:SEARCH=REPLACE%
27set result=%result:.=\.%
28
29:: http://stackoverflow.com/questions/2541767/what-is-the-proper-way-to-test-if-variable-is-empty-in-a-batch-file-if-not-1
30:: Make sure it is not the empty string or a string of spaces
31:: Test by setting result to space
32::set result=
33set result=%result: =%
34
35::if not "%result%" == ""
36::set result=^|%result%
37
[30038]38echo ^|%result%
39goto fin
40
41
42:done
[30036]43:: Echo a vertical bar up front, regardless of whether the result is empty
[30038]44echo %result%
45
46:fin
Note: See TracBrowser for help on using the repository browser.