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

Last change on this file since 31107 was 31107, checked in by ak19, 7 years ago

Fixing subtle and hard to track down mistake that had prevented rebuilding solr (demo) collection when using server machine's hostname instead of localhost on Windows. Previously the regex matching on IPv4 in ipconfig output would latch onto the last line that mentioned it, which was the IPv4 address of the ethernet. So the host IP still worked but not hostname when accessing the solr servlet. Now the regex forces the code to use the correct IPv4 address: the line that starts with IPv4 (which has 3 empty spaces in front of it) rather than any of the many other lines that merely contain the string IPv4 Address.

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